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: 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);
?>
See also token_name() .
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}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.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)
;