Created
April 19, 2024 22:41
-
-
Save perrelet/4633edcdfabb1fbdb57e0046444c7342 to your computer and use it in GitHub Desktop.
PHP Token Index Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function php_token_lookup ($token) { | |
$tokens = [ | |
T_ABSTRACT => 'T_ABSTRACT ==> abstract - Class Abstraction', | |
T_AND_EQUAL => 'T_AND_EQUAL ==> &= - assignment operators', | |
T_ARRAY => 'T_ARRAY ==> array() - array(), array syntax', | |
T_ARRAY_CAST => 'T_ARRAY_CAST ==> (array) - type-casting', | |
T_AS => 'T_AS ==> as - foreach', | |
T_BOOLEAN_AND => 'T_BOOLEAN_AND ==> && - logical operators', | |
T_BOOLEAN_OR => 'T_BOOLEAN_OR ==> || - logical operators', | |
T_BOOL_CAST => 'T_BOOL_CAST ==> (bool) or (boolean) - type-casting', | |
T_BREAK => 'T_BREAK ==> break - break', | |
T_CALLABLE => 'T_CALLABLE ==> callable - callable', | |
T_CASE => 'T_CASE ==> case - switch', | |
T_CATCH => 'T_CATCH ==> catch - Exceptions', | |
T_CLASS => 'T_CLASS ==> class - classes and objects', | |
T_CLASS_C => 'T_CLASS_C ==> __CLASS__ - magic constants', | |
T_CLONE => 'T_CLONE ==> clone - classes and objects', | |
T_CLOSE_TAG => 'T_CLOSE_TAG ==> ?> or %> - escaping from HTML', | |
T_COALESCE => 'T_COALESCE ==> ?? - comparison operators', | |
T_COMMENT => 'T_COMMENT ==> // or #, and /* */ - comments', | |
T_CONCAT_EQUAL => 'T_CONCAT_EQUAL ==> .= - assignment operators', | |
T_CONST => 'T_CONST ==> const - class constants', | |
T_CONSTANT_ENCAPSED_STRING => 'T_CONSTANT_ENCAPSED_STRING ==> "foo" or "bar" - string syntax', | |
T_CONTINUE => 'T_CONTINUE ==> continue - continue', | |
T_CURLY_OPEN => 'T_CURLY_OPEN ==> {$ - complex variable parsed syntax', | |
T_DEC => 'T_DEC ==> -- - incrementing/decrementing operators', | |
T_DECLARE => 'T_DECLARE ==> declare - declare', | |
T_DEFAULT => 'T_DEFAULT ==> default - switch', | |
T_DIR => 'T_DIR ==> __DIR__ - magic constants', | |
T_DIV_EQUAL => 'T_DIV_EQUAL ==> /= - assignment operators', | |
T_DNUMBER => 'T_DNUMBER ==> 0.12, etc. - floating point numbers', | |
T_DO => 'T_DO ==> do - do..while', | |
T_DOC_COMMENT => 'T_DOC_COMMENT ==> /** */ - PHPDoc style comments', | |
T_DOLLAR_OPEN_CURLY_BRACES => 'T_DOLLAR_OPEN_CURLY_BRACES ==> ${ - complex variable parsed syntax', | |
T_DOUBLE_ARROW => 'T_DOUBLE_ARROW ==> => - array syntax', | |
T_DOUBLE_CAST => 'T_DOUBLE_CAST ==> (real), (double) or (float) - type-casting', | |
T_DOUBLE_COLON => 'T_DOUBLE_COLON ==> :: - see T_PAAMAYIM_NEKUDOTAYIM below', | |
T_ECHO => 'T_ECHO ==> echo - echo', | |
T_ELLIPSIS => 'T_ELLIPSIS ==> ... - function arguments', | |
T_ELSE => 'T_ELSE ==> else - else', | |
T_ELSEIF => 'T_ELSEIF ==> elseif - elseif', | |
T_EMPTY => 'T_EMPTY ==> empty - empty()', | |
T_ENCAPSED_AND_WHITESPACE => 'T_ENCAPSED_AND_WHITESPACE ==> " $a" - constant part of string with variables', | |
T_ENDDECLARE => 'T_ENDDECLARE ==> enddeclare - declare, alternative syntax', | |
T_ENDFOR => 'T_ENDFOR ==> endfor - for, alternative syntax', | |
T_ENDFOREACH => 'T_ENDFOREACH ==> endforeach - foreach, alternative syntax', | |
T_ENDIF => 'T_ENDIF ==> endif - if, alternative syntax', | |
T_ENDSWITCH => 'T_ENDSWITCH ==> endswitch - switch, alternative syntax', | |
T_ENDWHILE => 'T_ENDWHILE ==> endwhile - while, alternative syntax', | |
T_END_HEREDOC => 'T_END_HEREDOC ==> - heredoc syntax', | |
T_EVAL => 'T_EVAL ==> eval() - eval()', | |
T_EXIT => 'T_EXIT ==> exit or die - exit(), die()', | |
T_EXTENDS => 'T_EXTENDS ==> extends - extends, classes and objects', | |
T_FILE => 'T_FILE ==> __FILE__ - magic constants', | |
T_FINAL => 'T_FINAL ==> final - Final Keyword', | |
T_FINALLY => 'T_FINALLY ==> finally - Exceptions', | |
T_FOR => 'T_FOR ==> for - for', | |
T_FOREACH => 'T_FOREACH ==> foreach - foreach', | |
T_FUNCTION => 'T_FUNCTION ==> function - functions', | |
T_FUNC_C => 'T_FUNC_C ==> __FUNCTION__ - magic constants', | |
T_GLOBAL => 'T_GLOBAL ==> global - variable scope', | |
T_GOTO => 'T_GOTO ==> goto - goto', | |
T_HALT_COMPILER => 'T_HALT_COMPILER ==> __halt_compiler() - __halt_compiler', | |
T_IF => 'T_IF ==> if - if', | |
T_IMPLEMENTS => 'T_IMPLEMENTS ==> implements - Object Interfaces', | |
T_INC => 'T_INC ==> =++ - incrementing/decrementing operators', | |
T_INCLUDE => 'T_INCLUDE ==> include - include', | |
T_INCLUDE_ONCE => 'T_INCLUDE_ONCE ==> include_once - include_once', | |
T_INLINE_HTML => 'T_INLINE_HTML ==> - text outside PHP', | |
T_INSTANCEOF => 'T_INSTANCEOF ==> instanceof - type operators', | |
T_INSTEADOF => 'T_INSTEADOF ==> insteadof - Traits', | |
T_INTERFACE => 'T_INTERFACE ==> interface - Object Interfaces', | |
T_INT_CAST => 'T_INT_CAST ==> (int) or (integer) - type-casting', | |
T_ISSET => 'T_ISSET ==> isset() - isset()', | |
T_IS_EQUAL => 'T_IS_EQUAL ==> == - comparison operators', | |
T_IS_GREATER_OR_EQUAL => 'T_IS_GREATER_OR_EQUAL ==> >= - comparison operators', | |
T_IS_IDENTICAL => 'T_IS_IDENTICAL ==> === - comparison operators', | |
T_IS_NOT_EQUAL => 'T_IS_NOT_EQUAL ==> != or <> - comparison operators', | |
T_IS_NOT_IDENTICAL => 'T_IS_NOT_IDENTICAL ==> !== - comparison operators', | |
T_IS_SMALLER_OR_EQUAL => 'T_IS_SMALLER_OR_EQUAL ==> <= - comparison operators', | |
T_LINE => 'T_LINE ==> __LINE__ - magic constants', | |
T_LIST => 'T_LIST ==> list() - list()', | |
T_LNUMBER => 'T_LNUMBER ==> 123, 012, 0x1ac, etc. - integers', | |
T_LOGICAL_AND => 'T_LOGICAL_AND ==> and - logical operators', | |
T_LOGICAL_OR => 'T_LOGICAL_OR ==> or - logical operators', | |
T_LOGICAL_XOR => 'T_LOGICAL_XOR ==> xor - logical operators', | |
T_METHOD_C => 'T_METHOD_C ==> __METHOD__ - magic constants', | |
T_MINUS_EQUAL => 'T_MINUS_EQUAL ==> -= - assignment operators', | |
T_MOD_EQUAL => 'T_MOD_EQUAL ==> %= - assignment operators', | |
T_MUL_EQUAL => 'T_MUL_EQUAL ==> *= - assignment operators', | |
T_NAMESPACE => 'T_NAMESPACE ==> namespace - namespaces', | |
T_NEW => 'T_NEW ==> new - classes and objects', | |
T_NS_C => 'T_NS_C ==> __NAMESPACE__ - namespaces', | |
T_NS_SEPARATOR => 'T_NS_SEPARATOR ==> \ - namespaces', | |
T_NUM_STRING => 'T_NUM_STRING ==> "$a[0]" - numeric array index inside string', | |
T_OBJECT_CAST => 'T_OBJECT_CAST ==> (object) - type-casting', | |
T_OBJECT_OPERATOR => 'T_OBJECT_OPERATOR ==> -> - classes and objects', | |
T_NULLSAFE_OBJECT_OPERATOR => 'T_NULLSAFE_OBJECT_OPERATOR ==> ?-> - classes and objects', | |
T_OPEN_TAG => 'T_OPEN_TAG ==> <?php, <? or <% - escaping from HTML', | |
T_OPEN_TAG_WITH_ECHO => 'T_OPEN_TAG_WITH_ECHO ==> <?= or <%= - escaping from HTML', | |
T_OR_EQUAL => 'T_OR_EQUAL ==> |= - assignment operators', | |
T_PAAMAYIM_NEKUDOTAYIM => 'T_PAAMAYIM_NEKUDOTAYIM ==> :: - ::. Also defined as T_DOUBLE_COLON.', | |
T_PLUS_EQUAL => 'T_PLUS_EQUAL ==> =+= - assignment operators', | |
T_POW => 'T_POW ==> ** - arithmetic operators', | |
T_POW_EQUAL => 'T_POW_EQUAL ==> **= - assignment operators', | |
T_PRINT => 'T_PRINT ==> print - print', | |
T_PRIVATE => 'T_PRIVATE ==> private - classes and objects', | |
T_PROTECTED => 'T_PROTECTED ==> protected - classes and objects', | |
T_PUBLIC => 'T_PUBLIC ==> public - classes and objects', | |
T_REQUIRE => 'T_REQUIRE ==> require - require', | |
T_REQUIRE_ONCE => 'T_REQUIRE_ONCE ==> require_once - require_once', | |
T_RETURN => 'T_RETURN ==> return - returning values', | |
T_SL => 'T_SL ==> << - bitwise operators', | |
T_SL_EQUAL => 'T_SL_EQUAL ==> <<= - assignment operators', | |
T_SPACESHIP => 'T_SPACESHIP ==> <=> - comparison operators', | |
T_SR => 'T_SR ==> >> - bitwise operators', | |
T_SR_EQUAL => 'T_SR_EQUAL ==> >>= - assignment operators', | |
T_START_HEREDOC => 'T_START_HEREDOC ==> <<< - heredoc syntax', | |
T_STATIC => 'T_STATIC ==> static - variable scope', | |
T_STRING => 'T_STRING ==> parent, self, etc. - identifiers, e.g. keywords like parent and self, function names, class names and more are matched. See also T_CONSTANT_ENCAPSED_STRING.', | |
T_STRING_CAST => 'T_STRING_CAST ==> (string) - type-casting', | |
T_STRING_VARNAME => 'T_STRING_VARNAME ==> "${a - complex variable parsed syntax', | |
T_SWITCH => 'T_SWITCH ==> switch - switch', | |
T_THROW => 'T_THROW ==> throw - Exceptions', | |
T_TRAIT => 'T_TRAIT ==> trait - Traits', | |
T_TRAIT_C => 'T_TRAIT_C ==> __TRAIT__ - __TRAIT__', | |
T_TRY => 'T_TRY ==> try - Exceptions', | |
T_UNSET => 'T_UNSET ==> unset() - unset()', | |
T_UNSET_CAST => 'T_UNSET_CAST ==> (unset) - type-casting', | |
T_USE => 'T_USE ==> use - namespaces', | |
T_VAR => 'T_VAR ==> var - classes and objects', | |
T_VARIABLE => 'T_VARIABLE ==> $foo - variables', | |
T_WHILE => 'T_WHILE ==> while - while, do..while', | |
T_WHITESPACE => 'T_WHITESPACE ==> \t \r\n - ', | |
T_XOR_EQUAL => 'T_XOR_EQUAL ==> ^= - assignment operators', | |
T_YIELD => 'T_YIELD ==> yield - generators', | |
T_YIELD_FROM => 'T_YIELD_FROM ==> yield from - generators', | |
]; | |
if (PHP_VERSION_ID > 70400) { | |
$tokens[T_BAD_CHARACTER] = 'T_BAD_CHARACTER ==> - anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available as of PHP 7.4.0)'; | |
$tokens[T_COALESCE_EQUAL] = 'T_COALESCE_EQUAL ==> ??= - assignment operators (available as of PHP 7.4.0)'; | |
$tokens[T_FN] = 'T_FN ==> fn - arrow functions (available as of PHP 7.4.0)'; | |
if (PHP_VERSION_ID > 80000) { | |
$tokens[T_ATTRIBUTE] = 'T_ATTRIBUTE ==> #[ - attributes (available as of PHP 8.0.0)'; | |
$tokens[T_MATCH] = 'T_MATCH ==> match - match (available as of PHP 8.0.0)'; | |
$tokens[T_NAME_FULLY_QUALIFIED] = 'T_NAME_FULLY_QUALIFIED ==> \App\Namespace - namespaces (available as of PHP 8.0.0)'; | |
$tokens[T_NAME_QUALIFIED] = 'T_NAME_QUALIFIED ==> App\Namespace - namespaces (available as of PHP 8.0.0)'; | |
$tokens[T_NAME_RELATIVE] = 'T_NAME_RELATIVE ==> namespace\Namespace - namespaces (available as of PHP 8.0.0)'; | |
if (PHP_VERSION_ID > 80100) { | |
$tokens[T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG] = 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG ==> & - Type declarations (available as of PHP 8.1.0)'; | |
$tokens[T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG] = 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG ==> & - Type declarations (available as of PHP 8.1.0)'; | |
$tokens[T_ENUM] = 'T_ENUM ==> enum - Enumerations (available as of PHP 8.1.0)'; | |
$tokens[T_READONLY] = 'T_READONLY ==> readonly - classes and objects (available as of PHP 8.1.0)'; | |
} | |
} | |
} | |
return isset($tokens[$token]) ? $tokens[$token] : "Unknown Token '{$token}'"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment