Doc #80772 [ReO]: No, I'm not supposed to know what T_SR means; table is missing new tokens

From: Date: Thu, 18 Feb 2021 22:31:28 +0000
Subject: Doc #80772 [ReO]: No, I'm not supposed to know what T_SR means; table is missing new tokens
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18570@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80772&edit=1 ID: 80772 Updated by: cmb@php.net Reported by: edg at greenberg dot org Summary: No, I'm not supposed to know what T_SR means; table is missing new tokens Status: Re-Opened Type: Documentation Problem Package: Scripting Engine problem Operating System: n/a PHP Version: 7.4.15 Block user comment: N Private report: N New Comment: > I'm not even sure what that's talking about. I was very confused about that as well, but Nikita clarified: > The point is that you shouldn't do something like > if (!defined('T_ENUM')) define('T_ENUM', VALUE_OF_T_ENUM_IN_PHP_8_1); Previous Comments: ------------------------------------------------------------------------ [2021-02-18 21:02:15] requinix@php.net > 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. That comment is years out of date: PHP 5.4 started showing the actual symbol in error messages along with the token name, and PHP 8.0 omits the token name entirely. https://wiki.php.net/rfc/improved-parser-error-message https://3v4l.org/n19iY > 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. I'm not even sure what that's talking about. > The example code conflicts (does exactly the wrong thing) with the warning on > documentation page: And I'm not sure what you meant by that, but I guess there was some misunderstanding. 1. That page needs some light editing. 2. The table is out of date - like, it's missing 8.0's T_ATTRIBUTE. https://github.com/php/php-src/blob/PHP-8.0.0/Zend/zend_language_parser.y ------------------------------------------------------------------------ [2021-02-18 19:54:38] edg at greenberg dot org I don't think I understood all I knew. Closing. ------------------------------------------------------------------------ [2021-02-18 16:58:50] edg at greenberg dot org Description: ------------ --- From manual page: https://php.net/tokenizer.examples --- The example code conflicts (does exactly the wrong thing) with the warning on documentation page: https://www.php.net/manual/en/tokens.php wherein it is written: 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 to T_TRAIT in PHP 5.4 and the value of T_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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80772&edit=1

« previous php.doc.bugs (#18570) next »