php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80772 No, I'm not supposed to know what T_SR means; table is missing new tokens
Submitted: 2021-02-18 16:58 UTC Modified: 2021-03-30 11:04 UTC
From: edg at greenberg dot org Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.4.15 OS: n/a
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: edg at greenberg dot org
New email:
PHP Version: OS:

 

 [2021-02-18 16:58 UTC] 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.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-18 19:54 UTC] edg at greenberg dot org
-Summary: Documentation pages for tokenizer conflict with each other +Summary: edg@greenberg.org -Status: Open +Status: Closed
 [2021-02-18 19:54 UTC] edg at greenberg dot org
I don't think I understood all I knew.  Closing.
 [2021-02-18 21:02 UTC] requinix@php.net
-Summary: edg@greenberg.org +Summary: No, I'm not supposed to know what T_SR means; table is missing new tokens -Status: Closed +Status: Re-Opened -Package: Unknown/Other Function +Package: Scripting Engine problem
 [2021-02-18 21:02 UTC] 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 22:31 UTC] cmb@php.net
> 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);
 [2021-03-30 11:04 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC