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.

Nota: 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.

<?php
// Prior to PHP 7.4.0, T_FN is not defined.
defined('T_FN') || define('T_FN', 10001);
?>

Tokens
Token Syntax Reference
T_ABSTRACT (int) abstract Astrazione delle classi
T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG (int) & Dichiarazioni di tipo (available as of PHP 8.1.0)
T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG (int) & Dichiarazioni di tipo (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) as foreach
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) break break
T_CALLABLE (int) callable callable
T_CASE (int) case switch
T_CATCH (int) catch Exceptions
T_CLASS (int) class classes and objects
T_CLASS_C (int) __CLASS__ magic constants
T_CLONE (int) clone classes 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) const class constants
T_CONSTANT_ENCAPSED_STRING (int) "foo" or 'bar' string syntax
T_CONTINUE (int) continue continue
T_CURLY_OPEN (int) {$ advanced variable string interpolation
T_DEC (int) -- incrementing/decrementing operators
T_DECLARE (int) declare declare
T_DEFAULT (int) default switch
T_DIR (int) __DIR__ magic constants
T_DIV_EQUAL (int) /= assignment operators
T_DNUMBER (int) 0.12, etc. floating point numbers
T_DO (int) do do..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) echo echo
T_ELLIPSIS (int) ... function arguments
T_ELSE (int) else else
T_ELSEIF (int) elseif elseif
T_EMPTY (int) empty empty()
T_ENCAPSED_AND_WHITESPACE (int) " $a" constant part of string with variables
T_ENDDECLARE (int) enddeclare declare, alternative syntax
T_ENDFOR (int) endfor for, alternative syntax
T_ENDFOREACH (int) endforeach foreach, alternative syntax
T_ENDIF (int) endif if, alternative syntax
T_ENDSWITCH (int) endswitch switch, alternative syntax
T_ENDWHILE (int) endwhile while, alternative syntax
T_ENUM (int) enum Enumerations (available as of PHP 8.1.0)
T_END_HEREDOC (int)   heredoc syntax
T_EVAL (int) eval() eval()
T_EXIT (int) exit or die exit(), die()
T_EXTENDS (int) extends extends, classes and objects
T_FILE (int) __FILE__ magic constants
T_FINAL (int) final Final Keyword
T_FINALLY (int) finally Exceptions
T_FN (int) fn arrow functions (available as of PHP 7.4.0)
T_FOR (int) for for
T_FOREACH (int) foreach foreach
T_FUNCTION (int) function functions
T_FUNC_C (int) __FUNCTION__ magic constants
T_GLOBAL (int) global variable scope
T_GOTO (int) goto goto
T_HALT_COMPILER (int) __halt_compiler() __halt_compiler
T_IF (int) if if
T_IMPLEMENTS (int) implements Object Interfaces
T_INC (int) ++ incrementing/decrementing operators
T_INCLUDE (int) include include
T_INCLUDE_ONCE (int) include_once include_once
T_INLINE_HTML (int)   text outside PHP
T_INSTANCEOF (int) instanceof type operators
T_INSTEADOF (int) insteadof Traits
T_INTERFACE (int) interface Object 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) and logical operators
T_LOGICAL_OR (int) or logical operators
T_LOGICAL_XOR (int) xor logical operators
T_MATCH (int) match match (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) namespace namespaces
T_NAME_FULLY_QUALIFIED (int) \App\Namespace namespaces (available as of PHP 8.0.0)
T_NAME_QUALIFIED (int) App\Namespace namespaces (available as of PHP 8.0.0)
T_NAME_RELATIVE (int) namespace\Namespace namespaces (available as of PHP 8.0.0)
T_NEW (int) new classes 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_PLUS_EQUAL (int) += assignment operators
T_POW (int) ** arithmetic operators
T_POW_EQUAL (int) **= assignment operators
T_PRINT (int) print print
T_PRIVATE (int) private classes and objects
T_PRIVATE_SET (int) private(set) property hooks (available as of PHP 8.4.0)
T_PROPERTY_C (int) __PROPERTY__ magic constants
T_PROTECTED (int) protected classes and objects
T_PROTECTED_SET (int) protected(set) property hooks (available as of PHP 8.4.0)
T_PUBLIC (int) public classes and objects
T_PUBLIC_SET (int) public(set) property hooks (available as of PHP 8.4.0)
T_READONLY (int) readonly classes and objects (available as of PHP 8.1.0)
T_REQUIRE (int) require require
T_REQUIRE_ONCE (int) require_once require_once
T_RETURN (int) return returning 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) static variable 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) "${a variable variables to interpolate in a string
T_SWITCH (int) switch switch
T_THROW (int) throw Exceptions
T_TRAIT (int) trait Traits
T_TRAIT_C (int) __TRAIT__ __TRAIT__
T_TRY (int) try Exceptions
T_UNSET (int) unset() unset()
T_UNSET_CAST (int) (unset) type-casting
T_USE (int) use namespaces
T_VAR (int) var classes and objects
T_VARIABLE (int) $foo variables
T_WHILE (int) while while, do..while
T_WHITESPACE (int) \t \r\n  
T_XOR_EQUAL (int) ^= assignment operators
T_YIELD (int) yield generators
T_YIELD_FROM (int) yield from generators

See also token_name().