php8.5
Home/ Manual/ appendices/ List of Parser Tokens

List of Parser Tokens

Various parts of the PHP language are represented internally by tokens. A code snippet that contains an invalid sequence of tokens may lead to errors like Parse error: syntax error, unexpected token "==", expecting "(" in script.php on line 10." where token == is internally represented by T_IS_EQUAL.

Various parts of the PHP language are represented internally by tokens. A code snippet that contains an invalid sequence of tokens may lead to errors like Parse error: syntax error, unexpected token "==", expecting "(" in script.php on line 10." where token == is internally represented by T_IS_EQUAL.

The following table lists all tokens. They are also available as PHP constants.

Note

T_* constants values are automatically generated based on PHP's underlying parser infrastructure. This means that the concrete value of a token may change between two PHP versions. This means that your code should never rely directly on the original T_* values taken from PHP version X.Y.Z, to provide some compatibility across multiple PHP versions.

To make use of T_* constants across multiple PHP versions, undefined constants may be defined by the user (using big numbers like 10000) with an appropriate strategy that will work with both PHP versions and T_* values.

php
<?php
// Prior to PHP 7.4.0, T_FN is not defined.
defined('T_FN') || define('T_FN', 10001);
?>
TokenSyntaxReference
T_ABSTRACT (int)abstractlanguage.oop5.abstract
T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG (int)&language.types.declarations (available as of PHP 8.1.0)
T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG (int)&language.types.declarations (available as of PHP 8.1.0)
T_AND_EQUAL (int)&=assignment operators
T_ARRAY (int)array()array(), array syntax
T_ARRAY_CAST (int)(array)type-casting
T_AS (int)asForeach
T_ATTRIBUTE (int)#[attributes (available as of PHP 8.0.0)
T_BAD_CHARACTER (int)anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) (available as of PHP 7.4.0)
T_BOOLEAN_AND (int)&&logical operators
T_BOOLEAN_OR (int)||logical operators
T_BOOL_CAST (int)(bool) or (boolean)type-casting
T_BREAK (int)breakbreak
T_CALLABLE (int)callablecallable
T_CASE (int)caseswitch
T_CATCH (int)catchlanguage.exceptions
T_CLASS (int)classclasses and objects
T_CLASS_C (int)__CLASS__magic constants
T_CLONE (int)cloneclasses and objects
T_CLOSE_TAG (int)?> or %>escaping from HTML
T_COALESCE (int)??comparison operators
T_COALESCE_EQUAL (int)??=assignment operators (available as of PHP 7.4.0)
T_COMMENT (int)// or #, and /* */comments
T_CONCAT_EQUAL (int).=assignment operators
T_CONST (int)constclass constants
T_CONSTANT_ENCAPSED_STRING (int)"foo" or 'bar'string syntax
T_CONTINUE (int)continuecontinue
T_CURLY_OPEN (int){$advanced variable string interpolation
T_DEC (int)--incrementing/decrementing operators
T_DECLARE (int)declaredeclare
T_DEFAULT (int)defaultswitch
T_DIR (int)__DIR__magic constants
T_DIV_EQUAL (int)/=assignment operators
T_DNUMBER (int)0.12, etc.floating point numbers
T_DO (int)dodo..while
T_DOC_COMMENT (int)/** */PHPDoc style comments
T_DOLLAR_OPEN_CURLY_BRACES (int)${basic variable string interpolation
T_DOUBLE_ARROW (int)=>array syntax
T_DOUBLE_CAST (int)(real), (double) or (float)type-casting
T_DOUBLE_COLON (int)::see T_PAAMAYIM_NEKUDOTAYIM below
T_ECHO (int)echoecho()
T_ELLIPSIS (int)...function arguments
T_ELSE (int)elseelse
T_ELSEIF (int)elseifelseif
T_EMPTY (int)emptyempty()
T_ENCAPSED_AND_WHITESPACE (int)" $a"constant part of string with variables
T_ENDDECLARE (int)enddeclaredeclare, alternative syntax
T_ENDFOR (int)endforfor, alternative syntax
T_ENDFOREACH (int)endforeachForeach, alternative syntax
T_ENDIF (int)endifif, alternative syntax
T_ENDSWITCH (int)endswitchswitch, alternative syntax
T_ENDWHILE (int)endwhilewhile, alternative syntax
T_ENUM (int)enumEnumerations (available as of PHP 8.1.0)
T_END_HEREDOC (int)heredoc syntax
T_EVAL (int)eval()eval()
T_EXIT (int)exit or dieexit(), die()
T_EXTENDS (int)extendsextends, classes and objects
T_FILE (int)__FILE__magic constants
T_FINAL (int)finallanguage.oop5.final
T_FINALLY (int)finallylanguage.exceptions
T_FN (int)fnarrow functions (available as of PHP 7.4.0)
T_FOR (int)forfor
T_FOREACH (int)foreachForeach
T_FUNCTION (int)functionfunctions
T_FUNC_C (int)__FUNCTION__magic constants
T_GLOBAL (int)globalvariable scope
T_GOTO (int)gotogoto
T_HALT_COMPILER (int)__halt_compiler()function.halt-compiler
T_IF (int)ifif
T_IMPLEMENTS (int)implementslanguage.oop5.interfaces
T_INC (int)++incrementing/decrementing operators
T_INCLUDE (int)includeinclude()
T_INCLUDE_ONCE (int)include_onceinclude_once()
T_INLINE_HTML (int)text outside PHP
T_INSTANCEOF (int)instanceoftype operators
T_INSTEADOF (int)insteadoflanguage.oop5.traits
T_INTERFACE (int)interfacelanguage.oop5.interfaces
T_INT_CAST (int)(int) or (integer)type-casting
T_ISSET (int)isset()isset()
T_IS_EQUAL (int)==comparison operators
T_IS_GREATER_OR_EQUAL (int)>=comparison operators
T_IS_IDENTICAL (int)===comparison operators
T_IS_NOT_EQUAL (int)!= or <>comparison operators
T_IS_NOT_IDENTICAL (int)!==comparison operators
T_IS_SMALLER_OR_EQUAL (int)<=comparison operators
T_LINE (int)__LINE__magic constants
T_LIST (int)list()list()
T_LNUMBER (int)123, 012, 0x1ac, etc.integers
T_LOGICAL_AND (int)andlogical operators
T_LOGICAL_OR (int)orlogical operators
T_LOGICAL_XOR (int)xorlogical operators
T_MATCH (int)matchMatch (available as of PHP 8.0.0)
T_METHOD_C (int)__METHOD__magic constants
T_MINUS_EQUAL (int)-=assignment operators
T_MOD_EQUAL (int)%=assignment operators
T_MUL_EQUAL (int)*=assignment operators
T_NAMESPACE (int)namespacenamespaces
T_NAME_FULLY_QUALIFIED (int)\App\Namespacenamespaces (available as of PHP 8.0.0)
T_NAME_QUALIFIED (int)App\Namespacenamespaces (available as of PHP 8.0.0)
T_NAME_RELATIVE (int)namespace\Namespacenamespaces (available as of PHP 8.0.0)
T_NEW (int)newclasses and objects
T_NS_C (int)__NAMESPACE__namespaces
T_NS_SEPARATOR (int)\namespaces
T_NUM_STRING (int)"$a[0]"numeric array index inside string
T_OBJECT_CAST (int)(object)type-casting
T_OBJECT_OPERATOR (int)->classes and objects
T_NULLSAFE_OBJECT_OPERATOR (int)?->classes and objects
T_OPEN_TAG (int)<?php, <? or <%escaping from HTML
T_OPEN_TAG_WITH_ECHO (int)<?= or <%=escaping from HTML
T_OR_EQUAL (int)|=assignment operators
T_PAAMAYIM_NEKUDOTAYIM (int)::scope resolution. Also defined as T_DOUBLE_COLON.
T_PIPE|>functional operators (available as of PHP 8.5.0)
T_PLUS_EQUAL (int)+=assignment operators
T_POW (int)**arithmetic operators
T_POW_EQUAL (int)**=assignment operators
T_PRINT (int)printprint()
T_PRIVATE (int)privateclasses and objects
T_PRIVATE_SET (int)private(set)property hooks (available as of PHP 8.4.0)
T_PROPERTY_C (int)__PROPERTY__magic constants (available as of PHP 8.4.0)
T_PROTECTED (int)protectedclasses and objects
T_PROTECTED_SET (int)protected(set)property hooks (available as of PHP 8.4.0)
T_PUBLIC (int)publicclasses and objects
T_PUBLIC_SET (int)public(set)property hooks (available as of PHP 8.4.0)
T_READONLY (int)readonlyclasses and objects (available as of PHP 8.1.0)
T_REQUIRE (int)requirerequire()
T_REQUIRE_ONCE (int)require_oncerequire_once()
T_RETURN (int)returnreturning values
T_SL (int)<<bitwise operators
T_SL_EQUAL (int)<<=assignment operators
T_SPACESHIP (int)<=>comparison operators
T_SR (int)>>bitwise operators
T_SR_EQUAL (int)>>=assignment operators
T_START_HEREDOC (int)<<<heredoc syntax
T_STATIC (int)staticvariable scope
T_STRING (int)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 (int)(string)type-casting
T_STRING_VARNAME (int)"${avariable variables to interpolate in a string
T_SWITCH (int)switchswitch
T_THROW (int)throwlanguage.exceptions
T_TRAIT (int)traitlanguage.oop5.traits
T_TRAIT_C (int)__TRAIT____TRAIT__
T_TRY (int)trylanguage.exceptions
T_UNSET (int)unset()unset()
T_UNSET_CAST (int)(unset)type-casting
T_USE (int)usenamespaces
T_VAR (int)varclasses and objects
T_VARIABLE (int)$foovariables
T_VOID_CAST(void)void cast (available as of PHP 8.5.0)
T_WHILE (int)whilewhile, do..while
T_WHITESPACE (int)\t \r\n
T_XOR_EQUAL (int)^=assignment operators
T_YIELD (int)yieldgenerators
T_YIELD_FROM (int)yield fromgenerators

See also token_name().

Source: appendices/tokens.xml · from the official PHP manual (php/doc-en)