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.
The following table lists all tokens. They are also available as PHP constants.
Usage of T_* constants
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.
TokensTokenSyntaxReferenceT_ABSTRACTabstractT_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG& (available as of PHP 8.1.0)T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG& (available as of PHP 8.1.0)T_AND_EQUAL&=assignment
operatorsT_ARRAYarray()array, array syntaxT_ARRAY_CAST(array)type-castingT_ASas&foreach;T_ATTRIBUTE#[attributes (available as of PHP 8.0.0)T_BAD_CHARACTER
anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d)
(available as of PHP 7.4.0)
T_BOOLEAN_AND&&logical operatorsT_BOOLEAN_OR||logical operatorsT_BOOL_CAST(bool) or (boolean)type-castingT_BREAKbreakbreakT_CALLABLEcallablecallableT_CASEcaseswitchT_CATCHcatchT_CLASSclassclasses and objectsT_CLASS_C__CLASS__
magic constants
T_CLONEclone
classes and objects
T_CLOSE_TAG?> or %>escaping
from HTMLT_COALESCE??
comparison operators
T_COALESCE_EQUAL??=
assignment operators
(available as of PHP 7.4.0)
T_COMMENT// or #, and /* */commentsT_CONCAT_EQUAL.=assignment
operatorsT_CONSTconstclass constantsT_CONSTANT_ENCAPSED_STRING"foo" or 'bar'string syntaxT_CONTINUEcontinuecontinueT_CURLY_OPEN{$complex
variable parsed syntaxT_DEC--incrementing/decrementing
operatorsT_DECLAREdeclaredeclareT_DEFAULTdefaultswitchT_DIR__DIR__magic constantsT_DIV_EQUAL/=assignment
operatorsT_DNUMBER0.12, etc.floating point numbersT_DOdodo..whileT_DOC_COMMENT/** */
PHPDoc style comments
T_DOLLAR_OPEN_CURLY_BRACES${complex
variable parsed syntaxT_DOUBLE_ARROW=>array syntaxT_DOUBLE_CAST(real), (double) or (float)type-castingT_DOUBLE_COLON::see T_PAAMAYIM_NEKUDOTAYIM belowT_ECHOechoechoT_ELLIPSIS...
function arguments
T_ELSEelseelseT_ELSEIFelseifelseifT_EMPTYemptyemptyT_ENCAPSED_AND_WHITESPACE" $a"constant part of
string with variablesT_ENDDECLAREenddeclaredeclare, alternative syntaxT_ENDFORendforfor, alternative syntaxT_ENDFOREACHendforeach&foreach;, alternative syntaxT_ENDIFendifif, alternative syntaxT_ENDSWITCHendswitchswitch, alternative syntaxT_ENDWHILEendwhilewhile, alternative syntaxT_ENUMenumEnumerations (available as of PHP 8.1.0)T_END_HEREDOCheredoc
syntaxT_EVALeval()evalT_EXITexit or dieexit, dieT_EXTENDSextendsextends, classes and objectsT_FILE__FILE__magic constantsT_FINALfinalT_FINALLYfinallyT_FNfn
arrow functions
(available as of PHP 7.4.0)
T_FORforforT_FOREACHforeach&foreach;T_FUNCTIONfunctionfunctionsT_FUNC_C__FUNCTION__
magic constants
T_GLOBALglobalvariable scopeT_GOTOgotogotoT_HALT_COMPILER__halt_compiler()T_IFififT_IMPLEMENTSimplementsT_INC++incrementing/decrementing
operatorsT_INCLUDEinclude()includeT_INCLUDE_ONCEinclude_once()include_onceT_INLINE_HTMLtext outside PHPT_INSTANCEOFinstanceof
type operators
T_INSTEADOFinsteadofT_INTERFACEinterfaceT_INT_CAST(int) or (integer)type-castingT_ISSETisset()issetT_IS_EQUAL==comparison operatorsT_IS_GREATER_OR_EQUAL>=comparison operatorsT_IS_IDENTICAL===comparison operatorsT_IS_NOT_EQUAL!= or <>comparison operatorsT_IS_NOT_IDENTICAL!==comparison operatorsT_IS_SMALLER_OR_EQUAL<=comparison operatorsT_LINE__LINE__magic constantsT_LISTlist()listT_LNUMBER123, 012, 0x1ac, etc.integersT_LOGICAL_ANDandlogical operatorsT_LOGICAL_ORorlogical operatorsT_LOGICAL_XORxorlogical operatorsT_MATCHmatch
match (available as of PHP 8.0.0)
T_METHOD_C__METHOD__
magic constants
T_MINUS_EQUAL-=assignment
operatorsT_MOD_EQUAL%=assignment
operatorsT_MUL_EQUAL*=assignment
operatorsT_NAMESPACEnamespace
namespaces
T_NAME_FULLY_QUALIFIED\App\Namespace
namespaces (available as of PHP 8.0.0)
T_NAME_QUALIFIEDApp\Namespace
namespaces (available as of PHP 8.0.0)
T_NAME_RELATIVEnamespace\Namespace
namespaces (available as of PHP 8.0.0)
T_NEWnewclasses and objectsT_NS_C__NAMESPACE__
namespaces
T_NS_SEPARATOR\
namespaces
T_NUM_STRING"$a[0]"numeric array index
inside stringT_OBJECT_CAST(object)type-castingT_OBJECT_OPERATOR->classes and objectsT_NULLSAFE_OBJECT_OPERATOR?->classes and objectsT_OPEN_TAG<?php, <? or <%escaping
from HTMLT_OPEN_TAG_WITH_ECHO<?= or <%=escaping
from HTMLT_OR_EQUAL|=assignment
operatorsT_PAAMAYIM_NEKUDOTAYIM::::. Also defined as
T_DOUBLE_COLON.T_PLUS_EQUAL+=assignment
operatorsT_POW**
arithmetic operators
T_POW_EQUAL**=
assignment operators
T_PRINTprint()printT_PRIVATEprivate
classes and objects
T_PROTECTEDprotected
classes and objects
T_PUBLICpublic
classes and objects
T_READONLYreadonly
classes and objects (available as of PHP 8.1.0)
T_REQUIRErequire()requireT_REQUIRE_ONCErequire_once()require_onceT_RETURNreturnreturning valuesT_SL<<bitwise
operatorsT_SL_EQUAL<<=assignment
operatorsT_SPACESHIP<=>
comparison operators
T_SR>>bitwise
operatorsT_SR_EQUAL>>=assignment
operatorsT_START_HEREDOC<<<heredoc
syntaxT_STATICstaticvariable scopeT_STRINGparent, 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(string)type-castingT_STRING_VARNAME"${acomplex
variable parsed syntaxT_SWITCHswitchswitchT_THROWthrowT_TRAITtraitT_TRAIT_C__TRAIT____TRAIT__T_TRYtryT_UNSETunset()unsetT_UNSET_CAST(unset)type-castingT_USEusenamespacesT_VARvarclasses and objectsT_VARIABLE$foovariablesT_WHILEwhilewhile, do..whileT_WHITESPACE\t \r\nT_XOR_EQUAL^=assignment
operatorsT_YIELDyieldgeneratorsT_YIELD_FROMyield fromgenerators