[PropertyAccess] Fix handling of uninitialized property of anonymous class#45002
Merged
Conversation
Member
nicolas-grekas
commented
Jan 12, 2022
| Q | A |
|---|---|
| Branch? | 4.4 |
| Bug fix? | yes |
| New feature? | no |
| Deprecations? | no |
| Tickets | Fix #44983 |
| License | MIT |
| Doc PR | - |
e55df72 to
27d5edf
Compare
Member
Author
|
Thank you @filiplikavcan. |
Contributor
|
This also affects 5.* and 6.* version. Will this PR be merged into those branches too? |
Member
Author
|
It is already, isn't it? |
Contributor
|
Ah, ok it is. It is not merged in 6.1 because there are conflict changes I suppose. Should I create a new PR for that or it is up to maintainers to resolve conflicts and merge it to 6.1? |
Member
Author
|
No need to, I'll handle the merge later on. |
This was referenced Jan 28, 2022
Merged
Merged
Merged
Merged
| // handle uninitialized properties in PHP >= 7.4 | ||
| if (\PHP_VERSION_ID >= 70400 && preg_match('/^Typed property ([\w\\\]+)::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches)) { | ||
| $r = new \ReflectionProperty($matches[1], $matches[2]); | ||
| if (\PHP_VERSION_ID >= 70400 && preg_match('/^Typed property ('.preg_quote(get_debug_type($object), '/').')::\$(\w+) must not be accessed before initialization$/', $e->getMessage(), $matches)) { |
Contributor
There was a problem hiding this comment.
This change introduced a new bug:
class X { public int $a; }
class Y extends X {}
(new Y)->a;This throws:
Typed property X::$a must not be accessed before initialization
but since get_debug_type(new Y) returns Y the error message does not match
Typed property Y::$a must not be accessed before initialization"
Here is a PR which fixes this: #45255
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.