Skip to content
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

Fix setRawValueWithoutLazyInitialization() / skipLazyInitialization() on initialized proxy #16344

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function test(string $name, object $obj) {
$reflector->initializeLazyObject($obj);
$reflector->getProperty('a')->setRawValueWithoutLazyInitialization($obj, 'test');

var_dump($obj->a);
var_dump($obj);
}

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

test('Proxy', $obj);

$real = new C('foo');
$obj = $reflector->newLazyProxy(function () use ($real) {
return $real;
});
$reflector->initializeLazyObject($obj);
$reflector->resetAsLazyProxy($real, function () {
return new C('bar');
});
$reflector->initializeLazyObject($real);

test('Nested Proxy', $obj);

?>
--EXPECTF--
# Ghost
string(4) "test"
object(C)#%d (2) {
["a"]=>
string(4) "test"
["b"]=>
NULL
}
# Proxy
string(4) "test"
lazy proxy object(C)#%d (1) {
["instance"]=>
object(C)#%d (2) {
["a"]=>
NULL
string(4) "test"
["b"]=>
NULL
}
}
# Nested Proxy
string(4) "test"
lazy proxy object(C)#%d (1) {
["instance"]=>
lazy proxy object(C)#%d (1) {
["instance"]=>
object(C)#%d (2) {
["a"]=>
string(4) "test"
["b"]=>
NULL
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ $obj = $reflector->newLazyProxy(function () {

test('Proxy', $obj);

$real = new C('foo');
$obj = $reflector->newLazyProxy(function () use ($real) {
return $real;
});
$reflector->initializeLazyObject($obj);
$reflector->resetAsLazyProxy($real, function () {
var_dump("initializer");
return new C('bar');
});
$reflector->initializeLazyObject($real);

test('Nested Proxy', $obj);

?>
--EXPECTF--
# Ghost
Expand All @@ -48,7 +61,7 @@ object(C)#%d (2) {
NULL
}
# Proxy
int(1)
int(2)
bool(true)
lazy proxy object(C)#%d (1) {
["instance"]=>
Expand All @@ -59,3 +72,19 @@ lazy proxy object(C)#%d (1) {
NULL
}
}
string(11) "initializer"
# Nested Proxy
int(2)
bool(true)
lazy proxy object(C)#%d (1) {
["instance"]=>
lazy proxy object(C)#%d (1) {
["instance"]=>
object(C)#%d (2) {
["a"]=>
int(2)
["b"]=>
NULL
}
}
}
13 changes: 11 additions & 2 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6205,6 +6205,11 @@ ZEND_METHOD(ReflectionProperty, setRawValueWithoutLazyInitialization)
RETURN_THROWS();
}

while (zend_object_is_lazy_proxy(object)
&& zend_lazy_object_initialized(object)) {
object = zend_lazy_object_get_instance(object);
}

zval *var_ptr = OBJ_PROP(object, ref->prop->offset);
bool prop_was_lazy = Z_PROP_FLAG_P(var_ptr) & IS_PROP_LAZY;

Expand Down Expand Up @@ -6248,12 +6253,16 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization)
RETURN_THROWS();
}

bool prop_was_lazy = (Z_PROP_FLAG_P(OBJ_PROP(object, ref->prop->offset)) & IS_PROP_LAZY);
while (zend_object_is_lazy_proxy(object)
&& zend_lazy_object_initialized(object)) {
object = zend_lazy_object_get_instance(object);
}

zval *src = &object->ce->default_properties_table[OBJ_PROP_TO_NUM(ref->prop->offset)];
zval *dst = OBJ_PROP(object, ref->prop->offset);
bool prop_was_lazy = (Z_PROP_FLAG_P(dst) & IS_PROP_LAZY);

if (!(Z_PROP_FLAG_P(dst) & IS_PROP_LAZY)) {
if (!prop_was_lazy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prop_was_lazy is used below, and always true. Is this correct? In that case, it should be dropped from the condition.

/* skipLazyInitialization has no effect on non-lazy properties */
return;
}
Expand Down