Repository navigation
Fix GH-25238: ReflectionProperty::isInitialized() skips lazy init once cached #25239
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f37346
Fix GH-25238: ReflectionProperty::isInitialized() skips lazy init onc…
lazerg ab0be44
Keep isInitialized() fast path for non-lazy objects and test lazy pro…
lazerg 20aba07
Cover warm cache fast path for non-lazy objects in GH-25238 test
lazerg bb34664
[ci skip] NEWS
arnaud-lb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --TEST-- | ||
| GH-25238 (ReflectionProperty::isInitialized() does not initialize lazy objects once its cache slot is warm) | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| class Line { | ||
| public string $label = ''; | ||
| } | ||
|
|
||
| class NoDefault { | ||
| public string $label; | ||
| } | ||
|
|
||
| $class = new ReflectionClass(Line::class); | ||
| $property = new ReflectionProperty(Line::class, 'label'); | ||
|
|
||
| foreach (['first', 'second', 'third'] as $label) { | ||
| $line = $class->newLazyGhost(function (Line $line) use ($label) { | ||
| $line->label = $label; | ||
| }); | ||
| var_dump($property->isInitialized($line)); | ||
| var_dump($class->isUninitializedLazyObject($line)); | ||
| var_dump($line->label); | ||
| } | ||
|
|
||
| foreach (['first', 'second'] as $label) { | ||
| $line = $class->newLazyProxy(function () use ($label) { | ||
| $line = new Line(); | ||
| $line->label = $label; | ||
| return $line; | ||
| }); | ||
| var_dump($property->isInitialized($line)); | ||
| var_dump($class->isUninitializedLazyObject($line)); | ||
| var_dump($property->isInitialized($line)); | ||
| var_dump($line->label); | ||
| } | ||
|
|
||
| $line = new Line(); | ||
| unset($line->label); | ||
| var_dump($property->isInitialized($line)); | ||
|
|
||
| $class = new ReflectionClass(NoDefault::class); | ||
| $property = new ReflectionProperty(NoDefault::class, 'label'); | ||
|
|
||
| for ($i = 0; $i < 2; $i++) { | ||
| $object = $class->newLazyGhost(function (NoDefault $object) {}); | ||
| var_dump($property->isInitialized($object)); | ||
| var_dump($class->isUninitializedLazyObject($object)); | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(false) | ||
| string(5) "first" | ||
| bool(true) | ||
| bool(false) | ||
| string(6) "second" | ||
| bool(true) | ||
| bool(false) | ||
| string(5) "third" | ||
| bool(true) | ||
| bool(false) | ||
| bool(true) | ||
| string(5) "first" | ||
| bool(true) | ||
| bool(false) | ||
| bool(true) | ||
| string(6) "second" | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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 only tests
newLazyGhost()where the property is initialized inside the callback, and missesnewLazyProxy()(both before and after initialization) as well as a lazy object whose initializer leaves the property uninitialized.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.
Added in ab0be44:
newLazyProxy()before and after initialization, and a ghost whose initializer leaves the property uninitialized. All of them fail without the fix.