Skip to content

Commit 0e66515

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: Fix GH-25238: ReflectionProperty::isInitialized() skips lazy init once cached (#25239)
2 parents 13b89e2 + 020d474 commit 0e66515

3 files changed

Lines changed: 81 additions & 3 deletions

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
of class names in implements, catch, and trait use lists. (Jorg Sowa)
99
. Fixed AST export dropping the braces of dynamic class constant fetches.
1010
(Jorg Sowa)
11+
. Fixed bug GH-25238 (ReflectionProperty::isInitialized() skips lazy init once
12+
cached). (lazerg)
1113

1214
- Curl:
1315
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)

‎ext/reflection/php_reflection.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ ZEND_METHOD(ReflectionFunctionAbstract, getAttributes)
20112011
const zend_function *fptr;
20122012

20132013
GET_REFLECTION_OBJECT_PTR(fptr);
2014-
2014+
20152015
uint32_t target;
20162016
if (fptr->common.scope && (fptr->common.fn_flags & (ZEND_ACC_CLOSURE|ZEND_ACC_FAKE_CLOSURE)) != ZEND_ACC_CLOSURE) {
20172017
target = ZEND_ATTRIBUTE_TARGET_METHOD;
@@ -3396,7 +3396,7 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, bool variadic
33963396
RETURN_THROWS();
33973397
}
33983398
object = NULL;
3399-
}
3399+
}
34003400
obj_ce = mptr->common.scope;
34013401
} else {
34023402
if (!object) {
@@ -6308,7 +6308,9 @@ ZEND_METHOD(ReflectionProperty, isInitialized)
63086308

63096309
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
63106310
zval *value = OBJ_PROP(Z_OBJ_P(object), prop_offset);
6311-
RETURN_BOOL(!Z_ISUNDEF_P(value));
6311+
if (EXPECTED(!Z_ISUNDEF_P(value) || !zend_object_is_lazy(Z_OBJ_P(object)))) {
6312+
RETURN_BOOL(!Z_ISUNDEF_P(value));
6313+
}
63126314
}
63136315
}
63146316

‎ext/reflection/tests/gh25238.phpt‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--TEST--
2+
GH-25238 (ReflectionProperty::isInitialized() does not initialize lazy objects once its cache slot is warm)
3+
--FILE--
4+
<?php
5+
6+
class Line {
7+
public string $label = '';
8+
}
9+
10+
class NoDefault {
11+
public string $label;
12+
}
13+
14+
$class = new ReflectionClass(Line::class);
15+
$property = new ReflectionProperty(Line::class, 'label');
16+
17+
foreach (['first', 'second', 'third'] as $label) {
18+
$line = $class->newLazyGhost(function (Line $line) use ($label) {
19+
$line->label = $label;
20+
});
21+
var_dump($property->isInitialized($line));
22+
var_dump($class->isUninitializedLazyObject($line));
23+
var_dump($line->label);
24+
}
25+
26+
foreach (['first', 'second'] as $label) {
27+
$line = $class->newLazyProxy(function () use ($label) {
28+
$line = new Line();
29+
$line->label = $label;
30+
return $line;
31+
});
32+
var_dump($property->isInitialized($line));
33+
var_dump($class->isUninitializedLazyObject($line));
34+
var_dump($property->isInitialized($line));
35+
var_dump($line->label);
36+
}
37+
38+
$line = new Line();
39+
unset($line->label);
40+
var_dump($property->isInitialized($line));
41+
42+
$class = new ReflectionClass(NoDefault::class);
43+
$property = new ReflectionProperty(NoDefault::class, 'label');
44+
45+
for ($i = 0; $i < 2; $i++) {
46+
$object = $class->newLazyGhost(function (NoDefault $object) {});
47+
var_dump($property->isInitialized($object));
48+
var_dump($class->isUninitializedLazyObject($object));
49+
}
50+
51+
?>
52+
--EXPECT--
53+
bool(true)
54+
bool(false)
55+
string(5) "first"
56+
bool(true)
57+
bool(false)
58+
string(6) "second"
59+
bool(true)
60+
bool(false)
61+
string(5) "third"
62+
bool(true)
63+
bool(false)
64+
bool(true)
65+
string(5) "first"
66+
bool(true)
67+
bool(false)
68+
bool(true)
69+
string(6) "second"
70+
bool(false)
71+
bool(false)
72+
bool(false)
73+
bool(false)
74+
bool(false)

0 commit comments

Comments
 (0)