Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.3 | Tokenizer/PHP: add support for readonly anonymous classes #309

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 28, 2024

Description

PHP 8.3 introduced readonly anonymous classes, fixing an oversight in the PHP 8.2 introduction of readonly classes.

As things were, for PHP 8.1+, the tokenizer would change the token code for the readonly keyword from T_READONLY to T_STRING in the "context sensitive keyword" layer, thinking it to be a class name.

And for PHP < 8.1, the readonly polyfill would ignore the token as it being preceded by the new keyword would be seen as conflicting with the "context sensitive keyword" layer, which meant it would not be re-tokenized from T_STRING to T_READONLY.

This commit fixes both.

Includes adding tests in a number of pre-existing test classes to cover this change.

Suggested changelog entry

  • Added
    • Support for PHP 8.3 readonly anonymous classes.

Related issues/external references

Related to #106

Types of changes

  • New feature (non-breaking change which adds functionality)

@jrfnl
Copy link
Member Author

jrfnl commented Jan 31, 2024

Unless there are objections/someone leaves a comments on this PR, I will merge this tomorrow.

PHP 8.3 introduced readonly anonymous classes, fixing an oversight in the PHP 8.2 introduction of readonly classes.

As things were, for PHP 8.1+, the tokenizer would change the token code for the `readonly` keyword from `T_READONLY` to `T_STRING` in the "context sensitive keyword" layer, thinking it to be a class name.

And for PHP < 8.1, the readonly polyfill would ignore the token as it being preceded by the `new` keyword would be seen as conflicting with the "context sensitive keyword" layer, which meant it would not be re-tokenized from `T_STRING` to `T_READONLY`.

This commit fixes both.

Includes adding tests in a number of pre-existing test classes to cover this change.
@jrfnl jrfnl force-pushed the php-8.3/tokenizer-readonly-anonymous-classes branch from 17293c7 to 9244858 Compare February 2, 2024 04:05
@jrfnl
Copy link
Member Author

jrfnl commented Feb 2, 2024

Rebased and made one more small tweak (limit the exception in the context sensitive keywords layer to strtolower($token[1]) === 'readonly'). Merging once the build passes.

@jrfnl jrfnl merged commit dc22022 into master Feb 2, 2024
44 checks passed
@jrfnl jrfnl deleted the php-8.3/tokenizer-readonly-anonymous-classes branch February 2, 2024 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant