Skip to content

Commit ea39c27

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix setRawValueWithoutLazyInitialization() and skipLazyInitialization() on initialized proxy
2 parents 02c2cfa + c310be0 commit ea39c27

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

Zend/tests/lazy_objects/setRawValueWithoutLazyInitialization_initialized.phpt

+30-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function test(string $name, object $obj) {
1717
$reflector->initializeLazyObject($obj);
1818
$reflector->getProperty('a')->setRawValueWithoutLazyInitialization($obj, 'test');
1919

20+
var_dump($obj->a);
2021
var_dump($obj);
2122
}
2223

@@ -33,22 +34,50 @@ $obj = $reflector->newLazyProxy(function () {
3334

3435
test('Proxy', $obj);
3536

37+
$real = new C('foo');
38+
$obj = $reflector->newLazyProxy(function () use ($real) {
39+
return $real;
40+
});
41+
$reflector->initializeLazyObject($obj);
42+
$reflector->resetAsLazyProxy($real, function () {
43+
return new C('bar');
44+
});
45+
$reflector->initializeLazyObject($real);
46+
47+
test('Nested Proxy', $obj);
48+
3649
?>
3750
--EXPECTF--
3851
# Ghost
52+
string(4) "test"
3953
object(C)#%d (2) {
4054
["a"]=>
4155
string(4) "test"
4256
["b"]=>
4357
NULL
4458
}
4559
# Proxy
60+
string(4) "test"
4661
lazy proxy object(C)#%d (1) {
4762
["instance"]=>
4863
object(C)#%d (2) {
4964
["a"]=>
50-
NULL
65+
string(4) "test"
5166
["b"]=>
5267
NULL
5368
}
5469
}
70+
# Nested Proxy
71+
string(4) "test"
72+
lazy proxy object(C)#%d (1) {
73+
["instance"]=>
74+
lazy proxy object(C)#%d (1) {
75+
["instance"]=>
76+
object(C)#%d (2) {
77+
["a"]=>
78+
string(4) "test"
79+
["b"]=>
80+
NULL
81+
}
82+
}
83+
}

Zend/tests/lazy_objects/skipLazyInitialization_initialized_object.phpt

+30-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ $obj = $reflector->newLazyProxy(function () {
3636

3737
test('Proxy', $obj);
3838

39+
$real = new C('foo');
40+
$obj = $reflector->newLazyProxy(function () use ($real) {
41+
return $real;
42+
});
43+
$reflector->initializeLazyObject($obj);
44+
$reflector->resetAsLazyProxy($real, function () {
45+
var_dump("initializer");
46+
return new C('bar');
47+
});
48+
$reflector->initializeLazyObject($real);
49+
50+
test('Nested Proxy', $obj);
51+
3952
?>
4053
--EXPECTF--
4154
# Ghost
@@ -48,7 +61,7 @@ object(C)#%d (2) {
4861
NULL
4962
}
5063
# Proxy
51-
int(1)
64+
int(2)
5265
bool(true)
5366
lazy proxy object(C)#%d (1) {
5467
["instance"]=>
@@ -59,3 +72,19 @@ lazy proxy object(C)#%d (1) {
5972
NULL
6073
}
6174
}
75+
string(11) "initializer"
76+
# Nested Proxy
77+
int(2)
78+
bool(true)
79+
lazy proxy object(C)#%d (1) {
80+
["instance"]=>
81+
lazy proxy object(C)#%d (1) {
82+
["instance"]=>
83+
object(C)#%d (2) {
84+
["a"]=>
85+
int(2)
86+
["b"]=>
87+
NULL
88+
}
89+
}
90+
}

ext/reflection/php_reflection.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -6005,6 +6005,11 @@ ZEND_METHOD(ReflectionProperty, setRawValueWithoutLazyInitialization)
60056005
RETURN_THROWS();
60066006
}
60076007

6008+
while (zend_object_is_lazy_proxy(object)
6009+
&& zend_lazy_object_initialized(object)) {
6010+
object = zend_lazy_object_get_instance(object);
6011+
}
6012+
60086013
zval *var_ptr = OBJ_PROP(object, ref->prop->offset);
60096014
bool prop_was_lazy = Z_PROP_FLAG_P(var_ptr) & IS_PROP_LAZY;
60106015

@@ -6048,7 +6053,10 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization)
60486053
RETURN_THROWS();
60496054
}
60506055

6051-
bool prop_was_lazy = (Z_PROP_FLAG_P(OBJ_PROP(object, ref->prop->offset)) & IS_PROP_LAZY);
6056+
while (zend_object_is_lazy_proxy(object)
6057+
&& zend_lazy_object_initialized(object)) {
6058+
object = zend_lazy_object_get_instance(object);
6059+
}
60526060

60536061
zval *src = &object->ce->default_properties_table[OBJ_PROP_TO_NUM(ref->prop->offset)];
60546062
zval *dst = OBJ_PROP(object, ref->prop->offset);
@@ -6063,7 +6071,7 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization)
60636071
ZVAL_COPY_PROP(dst, src);
60646072

60656073
/* Object becomes non-lazy if this was the last lazy prop */
6066-
if (prop_was_lazy && zend_object_is_lazy(object)
6074+
if (zend_object_is_lazy(object)
60676075
&& !zend_lazy_object_initialized(object)) {
60686076
if (zend_lazy_object_decr_lazy_props(object)) {
60696077
zend_lazy_object_realize(object);

0 commit comments

Comments
 (0)