List of Parser Tokens
Various parts of the PHP language are represented internally by types like T_SR. PHP outputs identifiers like this one in parse errors, like "Parse error: unexpected T_SR, expecting ',' or ';' in script.php on line 10."
You're supposed to know what T_SR means. For everybody who doesn't know that, here is a table with those identifiers, PHP-syntax and references to the appropriate places in the manual.
Note: Usage of T_* constants
All tokens listed below are also defined as PHP constants. Their value is automatically generated based on PHP's underlying parser infrastructure. This means that the concrete value of a token may change between two PHP versions. For example the
T_FILE
constant is 365 in PHP 5.3, while the same value refers now toT_TRAIT
in PHP 5.4 and the value ofT_FILE
is 369. 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. Instead your code should utilize custom values (using big numbers like 10000) and an appropriate strategy that will work with both PHP versions and T_* values.
Token | Syntax | Reference |
---|---|---|
T_ABSTRACT |
abstract | Class Abstraction |
T_AND_EQUAL |
&= | assignment operators |
T_ARRAY |
array() | array(), array syntax |
T_ARRAY_CAST |
(array) | type-casting |
T_AS |
as | foreach |
T_BAD_CHARACTER |
anything below ASCII 32 except \t (0x09), \n (0x0a) and \r (0x0d) | |
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_CHARACTER |
not used anymore | |
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 (available since PHP 7.0.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 |
{$ | complex variable parsed syntax |
T_DEC |
-- | incrementing/decrementing operators |
T_DECLARE |
declare | declare |
T_DEFAULT |
default | switch |
T_DIR |
__DIR__ | magic constants (available since PHP 5.3.0) |
T_DIV_EQUAL |
/= | assignment operators |
T_DNUMBER |
0.12, etc. | floating point numbers |
T_DOC_COMMENT |
/** */ | PHPDoc style comments |
T_DO |
do | do..while |
T_DOLLAR_OPEN_CURLY_BRACES |
${ | complex variable parsed syntax |
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 (available since PHP 5.6.0) |
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_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 (available since PHP 5.5.0) |
T_FOR |
for | for |
T_FOREACH |
foreach | foreach |
T_FUNCTION |
function or cfunction | functions |
T_FUNC_C |
__FUNCTION__ | magic constants |
T_GLOBAL |
global | variable scope |
T_GOTO |
goto | goto (available since PHP 5.3.0) |
T_HALT_COMPILER |
__halt_compiler() | __halt_compiler (available since PHP 5.1.0) |
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 (available since PHP 5.4.0) |
T_INT_CAST |
(int) or (integer) | type-casting |
T_INTERFACE |
interface | Object Interfaces |
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_SPACESHIP |
<=> | comparison operators (available since PHP 7.0.0) |
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_METHOD_C |
__METHOD__ | magic constants |
T_MINUS_EQUAL |
-= | assignment operators |
T_MOD_EQUAL |
%= | assignment operators |
T_MUL_EQUAL |
*= | assignment operators |
T_NAMESPACE |
namespace | namespaces (available since PHP 5.3.0) |
T_NS_C |
__NAMESPACE__ | namespaces (available since PHP 5.3.0) |
T_NS_SEPARATOR |
\ | namespaces (available since PHP 5.3.0) |
T_NEW |
new | classes and objects |
T_NUM_STRING |
"$a[0]" | numeric array index inside string |
T_OBJECT_CAST |
(object) | type-casting |
T_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 |
:: | ::. Also defined as
T_DOUBLE_COLON . |
T_PLUS_EQUAL |
+= | assignment operators |
T_POW |
** | arithmetic operators (available since PHP 5.6.0) |
T_POW_EQUAL |
**= | assignment operators (available since PHP 5.6.0) |
T_PRINT |
print() | |
T_PRIVATE |
private | classes and objects |
T_PUBLIC |
public | classes and objects |
T_PROTECTED |
protected | classes and objects |
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_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 | complex variable parsed syntax |
T_SWITCH |
switch | switch |
T_THROW |
throw | Exceptions |
T_TRAIT |
trait | Traits (available since PHP 5.4.0) |
T_TRAIT_C |
__TRAIT__ | __TRAIT__ (available since PHP 5.4.0) |
T_TRY |
try | Exceptions |
T_UNSET |
unset() | unset() |
T_UNSET_CAST |
(unset) | type-casting |
T_USE |
use | namespaces (available since PHP 5.3.0) |
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 (available since PHP 5.5.0) |
T_YIELD_FROM |
yield from | generators (available since PHP 7.0.0) |
See also token_name().
Vertaling niet beschikbaar
De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.
Als je de moed voelt, kun je je vertaling aanbieden ;-)
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-tokens.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.