-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[PropertyAccess] Fix handling of uninitialized property of anonymous class #45002
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
Conversation
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
Thank you @filiplikavcan. |
This also affects 5.* and 6.* version. Will this PR be merged into those branches too? |
It is already, isn't it? |
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? |
No need to, I'll handle the merge later on. |
@@ -436,11 +436,11 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid | |||
} | |||
} catch (\Error $e) { | |||
// 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)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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