feat: support asymmetric visibility in constructor promotion#297
Merged
calebdw merged 2 commits intoMar 19, 2026
Merged
Conversation
fd722b5 to
539f721
Compare
calebdw
approved these changes
Mar 19, 2026
PHP 8.4 allows asymmetric visibility on constructor promoted properties (e.g. `public private(set) string $name`), but the grammar only accepted a single visibility modifier in `property_promotion_parameter`. This adds an optional `set_visibility` field for the second modifier.
539f721 to
55bf24f
Compare
Collaborator
|
Thanks! I changed it from I also regenerated the grammar ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PHP 8.4 added asymmetric visibility which allows separate read/write visibility on properties. PR #258 added support for this on property declarations, but missed the case where two visibility modifiers are used in constructor promotion parameters.
This PR adds an optional
set_visibilityfield toproperty_promotion_parameterso that constructs like this parse correctly:Before:
private(set)/protected(set)in constructor promotion with a preceding visibility modifier produces a parse error.After: Parsed correctly as two
visibility_modifiernodes — one for read, one for write.Changes
common/define-grammar.js: Added optionalset_visibilityfield toproperty_promotion_parametertest/corpus/class.txt: Added test case for asymmetric visibility in constructor promotionphp/src/parser.c: RegeneratedTest plan
private(set) string $title)