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.2] Add readonly class support #834

Merged
merged 7 commits into from May 15, 2022

Conversation

TomasVotruba
Copy link
Contributor

@TomasVotruba TomasVotruba commented May 12, 2022

@TomasVotruba TomasVotruba changed the title add readonly class support [PHP 8.2] Add readonly class support May 12, 2022
@TomasVotruba TomasVotruba force-pushed the tv-readonly-class branch 2 times, most recently from 71a4045 to f34ec2c Compare May 12, 2022 18:02
@TomasVotruba
Copy link
Contributor Author

Ready for review 👍

@TomasVotruba TomasVotruba force-pushed the tv-readonly-class branch 2 times, most recently from ec1116b to 37b63f3 Compare May 12, 2022 18:08
Copy link
Owner

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a pretty printer test (and maybe pretty printer implementation -- not sure if this works out of the box).

test/code/parser/stmt/class/modifier.test Show resolved Hide resolved
grammar/php7.y Outdated Show resolved Hide resolved
@TomasVotruba
Copy link
Contributor Author

This is missing a pretty printer test (and maybe pretty printer implementation -- not sure if this works out of the box).

I've added simple print. Seems working as the modifier method is universal.

grammar/php7.y Outdated Show resolved Hide resolved
@TomasVotruba
Copy link
Contributor Author

Ready for review ✔️

@TomasVotruba TomasVotruba force-pushed the tv-readonly-class branch 3 times, most recently from ccf3d46 to 05018b8 Compare May 15, 2022 19:15
@TomasVotruba
Copy link
Contributor Author

I've added the custom check for class modifiers.

Let me know if that's ok. Otherwise good to review ✔️

@nikic
Copy link
Owner

nikic commented May 15, 2022

Can you please regenerate the Php7.php file to fix the merge conflict?

@TomasVotruba
Copy link
Contributor Author

Can you please regenerate the Php7.php file to fix the merge conflict?

Done 👍

@nikic nikic merged commit 678ccbe into nikic:master May 15, 2022
@TomasVotruba TomasVotruba deleted the tv-readonly-class branch May 15, 2022 21:20
@kocsismate
Copy link
Contributor

@TomasVotruba Thanks for the implementation! I've just noticed a slight difference between how properties of a readonly class is handled by php-src and PHP-Parser: while the former automatically assigns the readonly flag to any such property,
PHP-Parser doesn't do so. The behavior of php-src is highlighted at php/php-src#7305 (review)

Can we allow this inconsistency or should this be changed on PHP-Parser's part?

@TomasVotruba
Copy link
Contributor Author

Thank you, that's an interesting question.

So any property inside the readonly class should have implicit readonly modifier? How would you differ between implicit readonly modifier, when it comes to printer?

I think we have same convention for final classes. Their properties and methods are nor marked as final, even if PHP sees them this way.

Saying that, I think php-parser is different from php-src, as the former parsers what it sees (and nothing implicit) and later covers implicit behavior not to allow invalid run. Like wysiwyg vs. runtime.

Maybe different point of views: What real php-parser use case is negatively affected by this?

@kocsismate
Copy link
Contributor

Saying that, I think php-parser is different from php-src, as the former parsers what it sees (and nothing implicit) and later covers implicit behavior not to allow invalid run. Like wysiwyg vs. runtime.

Aha, it sounds like a good rule of thumb, and makes sense to me.

Maybe different point of views: What real php-parser use case is negatively affected by this?

Hmm, I'm not aware of any. Although, I'll have to adapt the readonly class support in my PR :)

P.S. @nikic Can you please make a PHP-Parser release so that I can update it in php-src?

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.

None yet

3 participants