[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Fri, 31 Jul 2026 19:57:49 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-140390@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-07-31T15:50:13-04:00 Commit: https://github.com/php/php-src/commit/dc875173c27d1fbd9d93ab0de959e4a18894a629 Raw diff: https://github.com/php/php-src/commit/dc875173c27d1fbd9d93ab0de959e4a18894a629.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Resolve the effective property in ReflectionProperty lazy APIs Changed paths: A Zend/tests/lazy_objects/isLazy_overridden_hooked_prop.phpt A Zend/tests/lazy_objects/skipLazyInitialization_overridden_hooked_prop.phpt M ext/reflection/php_reflection.c Diff: diff --git a/Zend/tests/lazy_objects/isLazy_overridden_hooked_prop.phpt b/Zend/tests/lazy_objects/isLazy_overridden_hooked_prop.phpt new file mode 100644 index 000000000000..615b9c2bb5c1 --- /dev/null +++ b/Zend/tests/lazy_objects/isLazy_overridden_hooked_prop.phpt @@ -0,0 +1,48 @@ +--TEST-- +Lazy Objects: ReflectionProperty::isLazy() with a hooked override +--FILE-- +<?php + +class B { + public $plain = 1; + public $virtual { get => 1; } + private $priv = 1; + public static $stat; +} + +class C extends B { + public $plain { get => $this->plain; set => $this->plain = $value; } + public $priv = 2; +} + +$reflector = new ReflectionClass(C::class); + +foreach (['Ghost', 'Proxy'] as $kind) { + printf("# %s:\n", $kind); + + $obj = $kind === 'Ghost' + ? $reflector->newLazyGhost(function ($obj) { }) + : $reflector->newLazyProxy(function ($obj) { return new C(); }); + + foreach (['plain', 'virtual', 'stat'] as $name) { + printf("%s: B scope %d, C scope %d\n", $name, + (new ReflectionProperty(B::class, $name))->isLazy($obj), + (new ReflectionProperty(C::class, $name))->isLazy($obj)); + } + + printf("priv: B scope %d\n", + (new ReflectionProperty(B::class, 'priv'))->isLazy($obj)); +} + +?> +--EXPECT-- +# Ghost: +plain: B scope 1, C scope 1 +virtual: B scope 0, C scope 0 +stat: B scope 0, C scope 0 +priv: B scope 1 +# Proxy: +plain: B scope 1, C scope 1 +virtual: B scope 0, C scope 0 +stat: B scope 0, C scope 0 +priv: B scope 1 diff --git a/Zend/tests/lazy_objects/skipLazyInitialization_overridden_hooked_prop.phpt b/Zend/tests/lazy_objects/skipLazyInitialization_overridden_hooked_prop.phpt new file mode 100644 index 000000000000..818bf17915d0 --- /dev/null +++ b/Zend/tests/lazy_objects/skipLazyInitialization_overridden_hooked_prop.phpt @@ -0,0 +1,36 @@ +--TEST-- +Lazy Objects: ReflectionProperty::skipLazyInitialization() with a hooked override +--FILE-- +<?php + +class B { + public $b = 1; +} + +class C extends B { + public $b { get => $this->b; set => $this->b = $value; } +} + +$reflector = new ReflectionClass(C::class); + +foreach (['Ghost', 'Proxy'] as $kind) { + printf("# %s:\n", $kind); + + $obj = $kind === 'Ghost' + ? $reflector->newLazyGhost(function ($obj) { $obj->b = 9; }) + : $reflector->newLazyProxy(function ($obj) { $c = new C(); $c->b = 9; return $c; }); + + (new ReflectionProperty(B::class, 'b'))->skipLazyInitialization($obj); + + printf("is lazy: %d\n", $reflector->isUninitializedLazyObject($obj)); + var_dump($obj->b); +} + +?> +--EXPECT-- +# Ghost: +is lazy: 0 +NULL +# Proxy: +is lazy: 0 +NULL diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index bcf75bfdf3de..9780a0368cf5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -6304,19 +6304,22 @@ ZEND_METHOD(ReflectionProperty, skipLazyInitialization) Z_PARAM_OBJ_OF_CLASS(object, intern->ce) } ZEND_PARSE_PARAMETERS_END(); - if (reflection_property_check_lazy_compatible(ref->prop, - ref->unmangled_name, intern, object, - "skipLazyInitialization") == FAILURE) { - RETURN_THROWS(); - } - 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); + zend_property_info *prop = reflection_property_get_effective_prop(ref, + intern->ce, object); + + if (reflection_property_check_lazy_compatible(prop, + ref->unmangled_name, intern, object, + "skipLazyInitialization") == FAILURE) { + RETURN_THROWS(); + } + + zval *src = &object->ce->default_properties_table[OBJ_PROP_TO_NUM(prop->offset)]; + zval *dst = OBJ_PROP(object, prop->offset); if (!(Z_PROP_FLAG_P(dst) & IS_PROP_LAZY)) { /* skipLazyInitialization has no effect on non-lazy properties */ @@ -6348,16 +6351,19 @@ ZEND_METHOD(ReflectionProperty, isLazy) Z_PARAM_OBJ_OF_CLASS(object, intern->ce) } ZEND_PARSE_PARAMETERS_END(); - if (!ref->prop || ref->prop->flags & (ZEND_ACC_STATIC | ZEND_ACC_VIRTUAL)) { - RETURN_FALSE; - } - while (zend_object_is_lazy_proxy(object) && zend_lazy_object_initialized(object)) { object = zend_lazy_object_get_instance(object); } - RETURN_BOOL(Z_PROP_FLAG_P(OBJ_PROP(object, ref->prop->offset)) & IS_PROP_LAZY); + const zend_property_info *prop = reflection_property_get_effective_prop(ref, + intern->ce, object); + + if (!prop || prop->flags & (ZEND_ACC_STATIC | ZEND_ACC_VIRTUAL)) { + RETURN_FALSE; + } + + RETURN_BOOL(Z_PROP_FLAG_P(OBJ_PROP(object, prop->offset)) & IS_PROP_LAZY); } /* {{{ Returns true if property was initialized */

« previous php.cvs (#140390) next »