Repository navigation
[Php80] Keep property type safe in ClassPropertyAssignToConstructorPromotionRector - #9049
Merged
Merged
Conversation
TomasVotruba
force-pushed
the
promotion-keep-property-type
branch
from
November 23, 2026 22:35
50b4df8 to
b51399e
Compare
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.
Promotion puts the param type on the property, which could change the property type in two unsafe ways.
1. Untyped public property in a final class got a native type with the default config
was changed to
public function __construct(public string $name = ''). An outside$person->name = nullthen throws a TypeError, and$person->name = 5silently becomes"5". Theinline_publicoption documents that without it a public/protected property is only promoted when typed, but the final class check returned early before that. Now the final class shortcut applies only to non-public properties (a protected one in a final class still promotes, as before).2. Property type narrowed to the param type, even with other writes
was changed to
private Circle $shape, soreset()throws a TypeError. Only literalnullwrites were guarded. Now when the param type differs from the property type, promotion is skipped if the property is assigned anywhere else in the class.Two
FixturePhp80fixtures relied on bug 1 - their property is now private, keeping what they test (the default value union).