Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PHP NEWS
of class names in implements, catch, and trait use lists. (Jorg Sowa)
. Fixed AST export dropping the braces of dynamic class constant fetches.
(Jorg Sowa)
. Fixed bug GH-25238 (ReflectionProperty::isInitialized() skips lazy init once
cached). (lazerg)

- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
Expand Down
4 changes: 3 additions & 1 deletion ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6488,7 +6488,9 @@ ZEND_METHOD(ReflectionProperty, isInitialized)

if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
zval *value = OBJ_PROP(Z_OBJ_P(object), prop_offset);
RETURN_BOOL(!Z_ISUNDEF_P(value));
if (EXPECTED(!Z_ISUNDEF_P(value) || !zend_object_is_lazy(Z_OBJ_P(object)))) {
RETURN_BOOL(!Z_ISUNDEF_P(value));
}
}
}

Expand Down
74 changes: 74 additions & 0 deletions ext/reflection/tests/gh25238.phpt
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));

@prateekbhujel prateekbhujel Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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 misses newLazyProxy() (both before and after initialization) as well as a lazy object whose initializer leaves the property uninitialized.

Copy link
Copy Markdown
Contributor Author

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.

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)
Loading