Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Sep 8, 2026

Copy link
Copy Markdown
Owner

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.

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
@iliaal

iliaal commented Sep 8, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php#23618.

@iliaal iliaal closed this Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant