1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix lazy proxy calling set hook twice
This commit is contained in:
Ilija Tovilo
2025-03-08 12:39:20 +01:00
2 changed files with 50 additions and 3 deletions

View File

@@ -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)

View File

@@ -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)