Skip to content

Fix lazy proxy calling set hook twice #18001

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

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
33 changes: 33 additions & 0 deletions Zend/tests/property_hooks/gh18000.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--TEST--
GH-18000: Lazy proxy calls set hook twice
--FILE--
<?php

class C {
public $prop {
set {
echo "set\n";
$this->prop = $value * 2;
}
}
}

$rc = new ReflectionClass(C::class);

$obj = $rc->newLazyProxy(function () {
echo "init\n";
return new C;
});

function foo(C $c) {
$c->prop = 1;
var_dump($c->prop);
}

foo($obj);

?>
--EXPECT--
set
init
int(2)
20 changes: 17 additions & 3 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,23 @@ static bool zend_is_in_hook(const zend_property_info *prop_info)

static bool zend_should_call_hook(const zend_property_info *prop_info, const zend_object *obj)
{
return !zend_is_in_hook(prop_info)
/* execute_data and This are guaranteed to be set if zend_is_in_hook() returns true. */
|| Z_OBJ(EG(current_execute_data)->This) != obj;
if (!zend_is_in_hook(prop_info)) {
return true;
}

/* execute_data and This are guaranteed to be set if zend_is_in_hook() returns true. */
zend_object *parent_obj = Z_OBJ(EG(current_execute_data)->This);
if (parent_obj == obj) {
return false;
}

if (zend_object_is_lazy_proxy(parent_obj)
&& zend_lazy_object_initialized(parent_obj)
&& zend_lazy_object_get_instance(parent_obj) == obj) {
return false;
}

return true;
}

static ZEND_COLD void zend_throw_no_prop_backing_value_access(zend_string *class_name, zend_string *prop_name, bool is_read)
Expand Down
Loading