Skip to content

Fix GH-23552: keyword class constant name not retagged to T_STRING - #23618

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-23552-tokenizer-feedback-8.4
Open

Fix GH-23552: keyword class constant name not retagged to T_STRING#23618
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/gh-23552-tokenizer-feedback-8.4

Conversation

@iliaal

@iliaal iliaal commented Sep 8, 2026

Copy link
Copy Markdown
Member

class F { const NEW = Bar::NEW; } reported T_NEW for the declared name under token_get_all($code, TOKEN_PARSE). The tokenizer resolved a parser feedback by searching the collected token list backwards for a matching token text, and since 8.3 typed class constants defer reducing the constant name past the initializer scan, so the declaration's feedback re-found the initializer's token. Matching the ident's source offset instead also corrects const NEW = NEW Bar();, where the text search retagged the NEW operator and left the declaration alone.

The offset is accumulated as tokens are emitted rather than derived from LANG_SCNG(yy_cursor). The unterminated-comment rule returns T_ERROR before recomputing yyleng, so the cursor overshoots the emitted length there; the test pins that input.

Fixes #23552

The tokenizer found the token a parser feedback applies to by scanning the
collected token list backwards for a matching token text. Typed class
constants defer reducing the constant name past the initializer scan, so for
`const NEW = Bar::NEW;` the declaration's feedback re-found the initializer's
token and left the declared name tagged T_NEW. Match the ident's source offset
instead, accumulated as tokens are emitted. Text matching also inverted
`const NEW = NEW Bar();`, retagging the NEW operator rather than the
declaration, and its search could not fail, so the store is now guarded rather
than asserted.

Fixes phpGH-23552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant