Merge branch 'PHP-8.4'

* PHP-8.4:
  Fix prop info fetching from prop slot with added hooks
This commit is contained in:
Ilija Tovilo 2025-04-08 18:46:01 +02:00
commit aa0c54dade
No known key found for this signature in database
GPG key ID: 5050C66BFCD1015A
3 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,23 @@
--TEST--
GH-18268: array_walk() on object with added property hooks
--FILE--
<?php
class A {
public $prop = 42;
}
class B extends A {
public $prop = 42 {
set {}
}
}
$b = new B;
array_walk($b, function (&$item) {
var_dump($item);
});
?>
--EXPECT--
int(42)

View file

@ -467,6 +467,8 @@ typedef struct _zend_property_info {
((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num))) ((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
#define OBJ_PROP_TO_NUM(offset) \ #define OBJ_PROP_TO_NUM(offset) \
(((offset) - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval)) (((offset) - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
#define OBJ_PROP_SLOT_TO_OFFSET(obj, slot) \
((uintptr_t)(slot) - (uintptr_t)(obj))
typedef struct _zend_class_constant { typedef struct _zend_class_constant {
zval value; /* flags are stored in u2 */ zval value; /* flags are stored in u2 */

View file

@ -203,7 +203,7 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ *
ZEND_API ZEND_COLD zend_property_info *zend_get_property_info_for_slot_slow(zend_object *obj, zval *slot) ZEND_API ZEND_COLD zend_property_info *zend_get_property_info_for_slot_slow(zend_object *obj, zval *slot)
{ {
uintptr_t offset = (uintptr_t)slot - (uintptr_t)obj->properties_table; uintptr_t offset = OBJ_PROP_SLOT_TO_OFFSET(obj, slot);
zend_property_info *prop_info; zend_property_info *prop_info;
ZEND_HASH_MAP_FOREACH_PTR(&obj->ce->properties_info, prop_info) { ZEND_HASH_MAP_FOREACH_PTR(&obj->ce->properties_info, prop_info) {
if (prop_info->offset == offset) { if (prop_info->offset == offset) {