[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Arnaud Le Blanc | Date: | Fri, 06 Nov 2026 16:15:30 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143367@lists.php.net to get a copy of this message | ||
Author: Arnaud Le Blanc (arnaud-lb)
Date: 2026-11-06T17:13:53+01:00
Commit: https://github.com/php/php-src/commit/0e66515c856834a93c2822b90014fca87770d671
Raw diff: https://github.com/php/php-src/commit/0e66515c856834a93c2822b90014fca87770d671.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
Fix GH-25238: ReflectionProperty::isInitialized() skips lazy init once cached (#25239)
Changed paths:
A ext/reflection/tests/gh25238.phpt
M NEWS
M ext/reflection/php_reflection.c
Diff:
diff --git a/NEWS b/NEWS
index b6b9a44d43ff..6b0564e2f0c0 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 5bdd5e18bf22..696828578fca 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -2011,7 +2011,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getAttributes)
const zend_function *fptr;
GET_REFLECTION_OBJECT_PTR(fptr);
-
+
uint32_t target;
if (fptr->common.scope && (fptr->common.fn_flags &
(ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE)) != ZEND_ACC_CLOSURE) {
target = ZEND_ATTRIBUTE_TARGET_METHOD;
@@ -3396,7 +3396,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, bool
variadic
RETURN_THROWS();
}
object = NULL;
- }
+ }
obj_ce = mptr->common.scope;
} else {
if (!object) {
@@ -6308,7 +6308,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));
+ }
}
}
diff --git a/ext/reflection/tests/gh25238.phpt b/ext/reflection/tests/gh25238.phpt
new file mode 100644
index 000000000000..24c4b754cabc
--- /dev/null
+++ b/ext/reflection/tests/gh25238.phpt
@@ -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)