Skip to content

Commit d20f4fc

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix properties_info_table for abstract properties
2 parents ff6c1c7 + c8cc233 commit d20f4fc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Zend/tests/gh19053.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-19053: Incorrect properties_info_table for abstract properties
3+
--FILE--
4+
<?php
5+
6+
abstract class GP {
7+
public abstract mixed $foo { get; }
8+
}
9+
10+
class P extends GP {
11+
public mixed $foo = 1;
12+
}
13+
14+
class C extends P {
15+
public mixed $foo { get => 2; }
16+
}
17+
18+
$c = new C;
19+
var_dump($c);
20+
21+
?>
22+
--EXPECTF--
23+
object(C)#%d (0) {
24+
["foo"]=>
25+
uninitialized(mixed)
26+
}

Zend/zend_inheritance.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,10 +1713,25 @@ void zend_build_properties_info_table(zend_class_entry *ce)
17131713
}
17141714
}
17151715

1716-
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
1716+
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, prop) {
17171717
if (prop->ce == ce && (prop->flags & ZEND_ACC_STATIC) == 0
17181718
&& !(prop->flags & ZEND_ACC_VIRTUAL)) {
1719-
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(!(prop->prototype->flags & ZEND_ACC_VIRTUAL) ? prop->prototype->offset : prop->offset);
1719+
const zend_property_info *root_prop = prop->prototype;
1720+
if (UNEXPECTED(root_prop->flags & ZEND_ACC_VIRTUAL)) {
1721+
/* Prototype is virtual, we need to manually hunt down the first backed property. */
1722+
root_prop = prop;
1723+
zend_class_entry *parent_ce;
1724+
while ((parent_ce = root_prop->ce->parent)) {
1725+
zend_property_info *parent_prop = zend_hash_find_ptr(&parent_ce->properties_info, key);
1726+
if (!parent_prop
1727+
|| parent_prop->prototype != prop->prototype
1728+
|| (parent_prop->flags & ZEND_ACC_VIRTUAL)) {
1729+
break;
1730+
}
1731+
root_prop = parent_prop;
1732+
}
1733+
}
1734+
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(root_prop->offset);
17201735
table[prop_table_offset] = prop;
17211736
}
17221737
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)