Documentation

Token
in package

FinalYes

Representation of single token.

As a token prototype you should understand a single element generated by token_get_all.

Tags
author

Dariusz Rumiński dariusz.ruminski@gmail.com

Table of Contents

Properties

$changed  : bool
Flag is token was changed.
$content  : string
Content of token prototype.
$id  : int|null
ID of token prototype, if available.
$isArray  : bool
If token prototype is an array.

Methods

__construct()  : mixed
equals()  : bool
Check if token is equals to given one.
equalsAny()  : bool
Check if token is equals to one of given.
getCastTokenKinds()  : array<int, int>
getClassyTokenKinds()  : array<int, int>
Get classy tokens kinds: T_CLASS, T_INTERFACE and T_TRAIT.
getContent()  : non-empty-string
Get token's content.
getId()  : int|null
Get token's id.
getKeywords()  : array<int, int>
Generate array containing all keywords that exists in PHP version in use.
getMagicConstants()  : array<int, int>
Generate array containing all predefined constants that exists in PHP version in use.
getName()  : null|string
Get token's name.
getNameForId()  : null|string
Get token's name.
getObjectOperatorKinds()  : array<int, int>
Get object operator tokens kinds: T_OBJECT_OPERATOR and (if available) T_NULLSAFE_OBJECT_OPERATOR.
getPrototype()  : array{: int, : string}|string
isArray()  : bool
Check if token prototype is an array.
isCast()  : bool
Check if token is one of type cast tokens.
isClassy()  : bool
Check if token is one of classy tokens: T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM.
isComment()  : bool
Check if token is one of comment tokens: T_COMMENT or T_DOC_COMMENT.
isGivenKind()  : bool
Check if token is one of given kind.
isKeyCaseSensitive()  : bool
A helper method used to find out whether a certain input token has to be case-sensitively matched.
isKeyword()  : bool
Check if token is a keyword.
isMagicConstant()  : bool
Returns if the token is of a Magic constants type.
isNativeConstant()  : bool
Check if token is a native PHP constant: true, false or null.
isObjectOperator()  : bool
Check if token is one of object operator tokens: T_OBJECT_OPERATOR or T_NULLSAFE_OBJECT_OPERATOR.
isWhitespace()  : bool
Check if token is whitespace.
toArray()  : array{id: int|null, name: string|null, content: string, isArray: bool, changed: bool}
toJson()  : string
getTokenKindsForNames()  : array<int, int>

Properties

$changed

Flag is token was changed.

private bool $changed = false

$content

Content of token prototype.

private string $content

$id

ID of token prototype, if available.

private int|null $id = null

$isArray

If token prototype is an array.

private bool $isArray

Methods

__construct()

public __construct(array{: int, : string}|string $token) : mixed
Parameters
$token : array{: int, : string}|string

token prototype

equals()

Check if token is equals to given one.

public equals(array{0: int, 1?: string}|string|Token $other[, bool $caseSensitive = true ]) : bool

If tokens are arrays, then only keys defined in parameter token are checked.

Parameters
$other : array{0: int, 1?: string}|string|Token

token or it's prototype

$caseSensitive : bool = true

perform a case sensitive comparison

Return values
bool

equalsAny()

Check if token is equals to one of given.

public equalsAny(array<int, array{0: int, 1?: string}|string|Token$others[, bool $caseSensitive = true ]) : bool
Parameters
$others : array<int, array{0: int, 1?: string}|string|Token>

array of tokens or token prototypes

$caseSensitive : bool = true

perform a case sensitive comparison

Return values
bool

getCastTokenKinds()

public static getCastTokenKinds() : array<int, int>
Return values
array<int, int>

getClassyTokenKinds()

Get classy tokens kinds: T_CLASS, T_INTERFACE and T_TRAIT.

public static getClassyTokenKinds() : array<int, int>
Return values
array<int, int>

getContent()

Get token's content.

public getContent() : non-empty-string

It shall be used only for getting the content of token, not for checking it against excepted value.

Return values
non-empty-string

getId()

Get token's id.

public getId() : int|null

It shall be used only for getting the internal id of token, not for checking it against excepted value.

Return values
int|null

getKeywords()

Generate array containing all keywords that exists in PHP version in use.

public static getKeywords() : array<int, int>
Return values
array<int, int>

getName()

Get token's name.

public getName() : null|string

It shall be used only for getting the name of token, not for checking it against excepted value.

Return values
null|string

token name

getNameForId()

Get token's name.

public static getNameForId(int $id) : null|string

It shall be used only for getting the name of token, not for checking it against excepted value.

Parameters
$id : int
Return values
null|string

token name

getObjectOperatorKinds()

Get object operator tokens kinds: T_OBJECT_OPERATOR and (if available) T_NULLSAFE_OBJECT_OPERATOR.

public static getObjectOperatorKinds() : array<int, int>
Return values
array<int, int>

getPrototype()

public getPrototype() : array{: int, : string}|string
Return values
array{: int, : string}|string

isArray()

Check if token prototype is an array.

public isArray() : bool
Return values
bool

is array

isCast()

Check if token is one of type cast tokens.

public isCast() : bool
Return values
bool

isClassy()

Check if token is one of classy tokens: T_CLASS, T_INTERFACE, T_TRAIT or T_ENUM.

public isClassy() : bool
Return values
bool

isComment()

Check if token is one of comment tokens: T_COMMENT or T_DOC_COMMENT.

public isComment() : bool
Return values
bool

isGivenKind()

Check if token is one of given kind.

public isGivenKind(int|array<int, int> $possibleKind) : bool
Parameters
$possibleKind : int|array<int, int>

kind or array of kinds

Return values
bool

isKeyCaseSensitive()

A helper method used to find out whether a certain input token has to be case-sensitively matched.

public static isKeyCaseSensitive(array<int, bool>|bool $caseSensitive, int $key) : bool
Parameters
$caseSensitive : array<int, bool>|bool

global case sensitiveness or an array of booleans, whose keys should match the ones used in $sequence. If any is missing, the default case-sensitive comparison is used

$key : int

the key of the token that has to be looked up

Tags
deprecated
Return values
bool

isKeyword()

Check if token is a keyword.

public isKeyword() : bool
Return values
bool

isNativeConstant()

Check if token is a native PHP constant: true, false or null.

public isNativeConstant() : bool
Return values
bool

isObjectOperator()

Check if token is one of object operator tokens: T_OBJECT_OPERATOR or T_NULLSAFE_OBJECT_OPERATOR.

public isObjectOperator() : bool
Return values
bool

isWhitespace()

Check if token is whitespace.

public isWhitespace([null|string $whitespaces = " " ]) : bool
Parameters
$whitespaces : null|string = " "

whitespace characters, default is " \t\n\r\0\x0B"

Return values
bool

toArray()

public toArray() : array{id: int|null, name: string|null, content: string, isArray: bool, changed: bool}
Return values
array{id: int|null, name: string|null, content: string, isArray: bool, changed: bool}

toJson()

public toJson() : string
Return values
string

getTokenKindsForNames()

private static getTokenKindsForNames(array<int, string> $tokenNames) : array<int, int>
Parameters
$tokenNames : array<int, string>
Return values
array<int, int>

        
On this page

Search results