Skip to content

Commit 30c8ceb

Browse files
committed
Fix properties_info_table for abstract properties
Fixes GH-19053
1 parent 0d19984 commit 30c8ceb

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-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: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,26 @@ void zend_build_properties_info_table(zend_class_entry *ce)
16871687
}
16881688
}
16891689

1690-
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
1690+
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, prop) {
16911691
if (prop->ce == ce && (prop->flags & ZEND_ACC_STATIC) == 0
16921692
&& !(prop->flags & ZEND_ACC_VIRTUAL)) {
1693-
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(!(prop->prototype->flags & ZEND_ACC_VIRTUAL) ? prop->prototype->offset : prop->offset);
1693+
const zend_property_info *root_prop = prop->prototype;
1694+
if (UNEXPECTED(root_prop->flags & ZEND_ACC_VIRTUAL)) {
1695+
/* Prototype is virtual, we need to manually hunt down the first backed property. */
1696+
root_prop = prop;
1697+
while (true) {
1698+
zend_class_entry *parent_ce = root_prop->ce->parent;
1699+
if (!parent_ce) { break; }
1700+
zend_property_info *parent_prop = zend_hash_find_ptr(&parent_ce->properties_info, key);
1701+
if (!parent_prop
1702+
|| parent_prop->prototype != prop->prototype
1703+
|| (parent_prop->flags & ZEND_ACC_VIRTUAL)) {
1704+
break;
1705+
}
1706+
root_prop = parent_prop;
1707+
}
1708+
}
1709+
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(root_prop->offset);
16941710
table[prop_table_offset] = prop;
16951711
}
16961712
} ZEND_HASH_FOREACH_END();

0 commit comments

Comments
 (0)