International PHP Conference Berlin 2025

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 abstract Astrazione delle classi
T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG & Dichiarazioni di tipo (available as of PHP 8.1.0)
T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG & Dichiarazioni di tipo (available as of PHP 8.1.0)
T_AND_EQUAL &= assignment operators
T_ARRAY array() array(), array syntax
T_ARRAY_CAST (array) type-casting
T_AS as 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 operators
T_BOOLEAN_OR || logical operators
T_BOOL_CAST (bool) or (boolean) type-casting
T_BREAK break break
T_CALLABLE callable callable
T_CASE case switch
T_CATCH catch Exceptions
T_CLASS class classes and objects
T_CLASS_C __CLASS__ magic constants
T_CLONE clone classes and objects
T_CLOSE_TAG ?> or %> escaping from HTML
T_COALESCE ?? comparison operators
T_COALESCE_EQUAL ??= assignment operators (available as of PHP 7.4.0)
T_COMMENT // or #, and /* */ comments
T_CONCAT_EQUAL .= assignment operators
T_CONST const class constants
T_CONSTANT_ENCAPSED_STRING "foo" or 'bar' string syntax
T_CONTINUE continue continue
T_CURLY_OPEN {$ advanced variable string interpolation
T_DEC -- incrementing/decrementing operators
T_DECLARE declare declare
T_DEFAULT default switch
T_DIR __DIR__ magic constants
T_DIV_EQUAL /= assignment operators
T_DNUMBER 0.12, etc. floating point numbers
T_DO do do..while
T_DOC_COMMENT /** */ PHPDoc style comments
T_DOLLAR_OPEN_CURLY_BRACES ${ basic variable string interpolation
T_DOUBLE_ARROW => array syntax
T_DOUBLE_CAST (real), (double) or (float) type-casting
T_DOUBLE_COLON :: see T_PAAMAYIM_NEKUDOTAYIM below
T_ECHO echo echo
T_ELLIPSIS ... function arguments
T_ELSE else else
T_ELSEIF elseif elseif
T_EMPTY empty empty()
T_ENCAPSED_AND_WHITESPACE " $a" constant part of string with variables
T_ENDDECLARE enddeclare declare, alternative syntax
T_ENDFOR endfor for, alternative syntax
T_ENDFOREACH endforeach foreach, alternative syntax
T_ENDIF endif if, alternative syntax
T_ENDSWITCH endswitch switch, alternative syntax
T_ENDWHILE endwhile while, alternative syntax
T_ENUM enum Enumerations (available as of PHP 8.1.0)
T_END_HEREDOC   heredoc syntax
T_EVAL eval() eval()
T_EXIT exit or die exit(), die()
T_EXTENDS extends extends, classes and objects
T_FILE __FILE__ magic constants
T_FINAL final Final Keyword
T_FINALLY finally Exceptions
T_FN fn arrow functions (available as of PHP 7.4.0)
T_FOR for for
T_FOREACH foreach foreach
T_FUNCTION function functions
T_FUNC_C __FUNCTION__ magic constants
T_GLOBAL global variable scope
T_GOTO goto goto
T_HALT_COMPILER __halt_compiler() __halt_compiler
T_IF if if
T_IMPLEMENTS implements Object Interfaces
T_INC ++ incrementing/decrementing operators
T_INCLUDE include include
T_INCLUDE_ONCE include_once include_once
T_INLINE_HTML   text outside PHP
T_INSTANCEOF instanceof type operators
T_INSTEADOF insteadof Traits
T_INTERFACE interface Object Interfaces
T_INT_CAST (int) or (integer) type-casting
T_ISSET isset() isset()
T_IS_EQUAL == comparison operators
T_IS_GREATER_OR_EQUAL >= comparison operators
T_IS_IDENTICAL === comparison operators
T_IS_NOT_EQUAL != or <> comparison operators
T_IS_NOT_IDENTICAL !== comparison operators
T_IS_SMALLER_OR_EQUAL <= comparison operators
T_LINE __LINE__ magic constants
T_LIST list() list()
T_LNUMBER 123, 012, 0x1ac, etc. integers
T_LOGICAL_AND and logical operators
T_LOGICAL_OR or logical operators
T_LOGICAL_XOR xor logical operators
T_MATCH match match (available as of PHP 8.0.0)
T_METHOD_C __METHOD__ magic constants
T_MINUS_EQUAL -= assignment operators
T_MOD_EQUAL %= assignment operators
T_MUL_EQUAL *= assignment operators
T_NAMESPACE namespace namespaces
T_NAME_FULLY_QUALIFIED \App\Namespace namespaces (available as of PHP 8.0.0)
T_NAME_QUALIFIED App\Namespace namespaces (available as of PHP 8.0.0)
T_NAME_RELATIVE namespace\Namespace namespaces (available as of PHP 8.0.0)
T_NEW new classes and objects
T_NS_C __NAMESPACE__ namespaces
T_NS_SEPARATOR \ namespaces
T_NUM_STRING "$a[0]" numeric array index inside string
T_OBJECT_CAST (object) type-casting
T_OBJECT_OPERATOR -> classes and objects
T_NULLSAFE_OBJECT_OPERATOR ?-> classes and objects
T_OPEN_TAG <?php, <? or <% escaping from HTML
T_OPEN_TAG_WITH_ECHO <?= or <%= escaping from HTML
T_OR_EQUAL |= assignment operators
T_PAAMAYIM_NEKUDOTAYIM :: scope resolution. Also defined as T_DOUBLE_COLON.
T_PLUS_EQUAL += assignment operators
T_POW ** arithmetic operators
T_POW_EQUAL **= assignment operators
T_PRINT print print
T_PRIVATE private classes and objects
T_PRIVATE_SET private(set) property hooks (available as of PHP 8.4.0)
T_PROTECTED protected classes and objects
T_PROTECTED_SET protected(set) property hooks (available as of PHP 8.4.0)
T_PUBLIC public classes and objects
T_PUBLIC_SET public(set) property hooks (available as of PHP 8.4.0)
T_READONLY readonly classes and objects (available as of PHP 8.1.0)
T_REQUIRE require require
T_REQUIRE_ONCE require_once require_once
T_RETURN return returning values
T_SL << bitwise operators
T_SL_EQUAL <<= assignment operators
T_SPACESHIP <=> comparison operators
T_SR >> bitwise operators
T_SR_EQUAL >>= assignment operators
T_START_HEREDOC <<< heredoc syntax
T_STATIC static variable scope
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 (string) type-casting
T_STRING_VARNAME "${a variable variables to interpolate in a string
T_SWITCH switch switch
T_THROW throw Exceptions
T_TRAIT trait Traits
T_TRAIT_C __TRAIT__ __TRAIT__
T_TRY try Exceptions
T_UNSET unset() unset()
T_UNSET_CAST (unset) type-casting
T_USE use namespaces
T_VAR var classes and objects
T_VARIABLE $foo variables
T_WHILE while while, do..while
T_WHITESPACE \t \r\n  
T_XOR_EQUAL ^= assignment operators
T_YIELD yield generators
T_YIELD_FROM yield from generators

See also token_name().

add a note

User Contributed Notes 3 notes

up
2
daniel_rhodes at yahoo dot co dot uk
8 months ago
In the above table of Tokens, it's worth noting that the bracketed text of "available as of PHP x.y.z" can mean one of two things:

[] This *parser token* is available as of PHP x.y.z
{eg. T_BAD_CHARACTER, T_NAME_QUALIFIED}

[] This *language feature* is available as of PHP x.y.z
{eg. T_ATTRIBUTE, T_COALESCE_EQUAL}
up
7
nathan at unfinitydesign dot com
16 years ago
T_ENCAPSED_AND_WHITESPACE is whitespace which intersects a group of tokens. For example, an "unexpected T_ENCAPSED_AND_WHITESPACE" error is produced by the following code:

<?php
$main_output_world
= 'snakes!';
echo(
'There are' 10 $main_output_world);
?>

Note the missing concatenation operator between the two strings leads to the whitespace error that is so named above. The concatenation operator instructs PHP to ignore the whitespace between the two code tokens (the so named "encapsed" data"), rather than parse it as a token itself.

The correct code would be:

<?php
$main_output_world
= 'snakes!';
echo(
'There are' . 10 . $main_output_world);
?>

Note the addition of the concatenation operator between each token.
up
-3
fgm at osinet dot fr
16 years ago
T_ENCAPSED_AND_WHITESPACED is returned when parsing strings with evaluated content, like "some $value" or this example from the Strings reference page:

<?php
echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some
{$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>

This last example is tokenized as:
T_ECHO
echo
T_WHITESPACE
%20 (a space character)
T_START_HEREDOC
<<
T_ENCAPSED_AND_WHITESPACE
My name is "
T_VARIABLE
$name
T_ENCAPSED_AND_WHITESPACE
". I am printing some
T_VARIABLE
$foo
T_OBJECT_OPERATOR
->
T_STRING
foo
T_ENCAPSED_AND_WHITESPACE
. Now, I am printing some
T_CURLY_OPEN
{
T_VARIABLE
$foo
T_OBJECT_OPERATOR
->
T_STRING
bar
(terminal)
[
T_LNUMBER
1
(terminal)
]
(terminal)
}
T_ENCAPSED_AND_WHITESPACE
. This should print a capital 'A': \x41
T_END_HEREDOC
EOT
(terminal)
;
To Top