[Php80] Skip promoting a property the parent declares without a native type - #8232
Merged
TomasVotruba merged 1 commit intoJul 30, 2026
Conversation
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.
Promoting a property that a parent declares without a native type produces code PHP refuses to load.
A child may redeclare an inherited untyped property, but it may not add a type to it. Promotion moves the parameter type onto the property, so it does exactly that:
becomes
which fatals on load:
This is not caught by the existing skips: the property is typed neither in the child nor via a conflicting docblock, so nothing signals the clash — the constraint lives entirely in the ancestor.
The fix
Skip promotion when the nearest ancestor declaring the property has no native type on it:
It returns on the first ancestor that declares the property, since that is the declaration the child must stay compatible with. A parent property that is natively typed keeps promoting as before — the child simply has to repeat the same type, which promotion already does.
Test
skip_untyped_parent_property.php.incwith anUntypedPropertyParentsource class. Verified it reproduces the bug: with the rule reverted the fixture fails —— and passes with the fix:
OK (56 tests, 57 assertions).Found while running Rector over a codebase where API controllers inherit an untyped
protected $modelfrom a shared base controller; every promoted child became unloadable.