PhpToken
class PhpToken implements Stringable (View source)
A class for working with PHP tokens, which is an alternative to the {token_get_all()} function.
Properties
int | $id | One of the T_* constants, or an integer < 256 representing a single-char token. |
|
string | $text | The textual content of the token. |
|
int | $line | The starting line number (1-based) of the token. |
|
int | $pos | The starting position (0-based) in the tokenized string. |
Methods
No description
Get the name of the token.
Same as {token_get_all()}, but returning array of {PhpToken} or an instance of a child class.
Whether the token has the given ID, the given text, or has an ID/text part of the given array.
Whether this token would be ignored by the PHP parser.
Magic method {https://www.php.net/manual/en/language.oop5.magic.php#object.tostring} allows a class to decide how it will react when it is treated like a string.
Details
final
__construct(int $id, string $text, int $line = -1, int $pos = -1)
No description
string|null
getTokenName()
Get the name of the token.
static array
tokenize(string $code, int $flags = 0)
Same as {token_get_all()}, but returning array of {PhpToken} or an instance of a child class.
bool
is(int|string|array $kind)
Whether the token has the given ID, the given text, or has an ID/text part of the given array.
bool
isIgnorable()
Whether this token would be ignored by the PHP parser.
string
__toString()
Magic method {https://www.php.net/manual/en/language.oop5.magic.php#object.tostring} allows a class to decide how it will react when it is treated like a string.