Documentation

Token
in package

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

$changed  : bool
Flag is token was changed.
$content  : string
Content of token prototype.
$id  : null|int
ID of token prototype, if available.
$isArray  : bool
If token prototype is an array.
__construct()  : mixed
clear()  : mixed
Clear token at given index.
clearChanged()  : mixed
Clear internal flag if token was changed.
equals()  : bool
Check if token is equals to given one.
equalsAny()  : bool
Check if token is equals to one of given.
getCastTokenKinds()  : array<string|int, int>
getClassyTokenKinds()  : array<string|int, int>
Get classy tokens kinds: T_CLASS, T_INTERFACE and T_TRAIT.
getContent()  : string
Get token's content.
getId()  : null|int
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<string|int, int>
Get object operator tokens kinds: T_OBJECT_OPERATOR and (if available) T_NULLSAFE_OBJECT_OPERATOR.
getPrototype()  : array<string|int, mixed>|string
isArray()  : bool
Check if token prototype is an array.
isCast()  : bool
Check if token is one of type cast tokens.
isChanged()  : bool
Check if token was changed.
isClassy()  : bool
Check if token is one of classy tokens: T_CLASS, T_INTERFACE or T_TRAIT.
isComment()  : bool
Check if token is one of comment tokens: T_COMMENT or T_DOC_COMMENT.
isEmpty()  : bool
Check if token is empty, e.g. because of clearing.
isGivenKind()  : bool
Check if token is one of given kind.
isKeyCaseSensitive()  : bool
A helper method used to find out whether or not 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.
override()  : mixed
Override token.
setContent()  : mixed
toArray()  : mixed
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 null|int $id

$isArray

If token prototype is an array.

private bool $isArray

Methods

__construct()

public __construct(array<string|int, mixed>|string $token) : mixed
Parameters
$token : array<string|int, mixed>|string

token prototype

Return values
mixed

clear()

Clear token at given index.

public clear() : mixed

Clearing means override token by empty string.

Tags
deprecated

since 2.4

Return values
mixed

clearChanged()

Clear internal flag if token was changed.

public clearChanged() : mixed
Tags
deprecated

since 2.4

Return values
mixed

equals()

Check if token is equals to given one.

public equals(array<string|int, mixed>|string|Token $other[, bool $caseSensitive = true ]) : bool

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

Parameters
$other : array<string|int, mixed>|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<string|int, mixed> $others[, bool $caseSensitive = true ]) : bool
Parameters
$others : array<string|int, mixed>

array of tokens or token prototypes

$caseSensitive : bool = true

perform a case sensitive comparison

Return values
bool

getCastTokenKinds()

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

getClassyTokenKinds()

Get classy tokens kinds: T_CLASS, T_INTERFACE and T_TRAIT.

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

getContent()

Get token's content.

public getContent() : string

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

Return values
string

getId()

Get token's id.

public getId() : null|int

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

Return values
null|int

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<string|int, int>
Return values
array<string|int, int>

getPrototype()

public getPrototype() : array<string|int, mixed>|string
Return values
array<string|int, mixed>|string

token prototype

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

isChanged()

Check if token was changed.

public isChanged() : bool
Tags
deprecated

since 2.4

Return values
bool

isClassy()

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

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

isEmpty()

Check if token is empty, e.g. because of clearing.

public isEmpty() : bool
Tags
deprecated

since 2.4

Return values
bool

isGivenKind()

Check if token is one of given kind.

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

kind or array of kinds

Return values
bool

isKeyCaseSensitive()

A helper method used to find out whether or not 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 $others. If any is missing, the default case-sensitive comparison is used

$key : int

the key of the token that has to be looked up

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

override()

Override token.

public override(array<string|int, mixed>|string|Token $other) : mixed

If called on Token inside Tokens collection please use Tokens::overrideAt instead.

Parameters
$other : array<string|int, mixed>|string|Token

token prototype

Tags
deprecated

since 2.4

Return values
mixed

setContent()

public setContent(string $content) : mixed
Parameters
$content : string
Tags
deprecated

since 2.4

Return values
mixed

toArray()

public toArray() : mixed
Return values
mixed

toJson()

public toJson([null|array<string|int, string> $options = null ]) : string
Parameters
$options : null|array<string|int, string> = null

JSON encode option

Return values
string

getTokenKindsForNames()

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

Search results