Skip to content

Fix properties_info_table for abstract properties #19140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: PHP-8.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Zend/tests/gh19053.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-19053: Incorrect properties_info_table for abstract properties
--FILE--
<?php

abstract class GP {
public abstract mixed $foo { get; }
}

class P extends GP {
public mixed $foo = 1;
}

class C extends P {
public mixed $foo { get => 2; }
}

$c = new C;
var_dump($c);

?>
--EXPECTF--
object(C)#%d (0) {
["foo"]=>
uninitialized(mixed)
}
20 changes: 18 additions & 2 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,10 +1687,26 @@ void zend_build_properties_info_table(zend_class_entry *ce)
}
}

ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&ce->properties_info, zend_string *key, prop) {
if (prop->ce == ce && (prop->flags & ZEND_ACC_STATIC) == 0
&& !(prop->flags & ZEND_ACC_VIRTUAL)) {
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(!(prop->prototype->flags & ZEND_ACC_VIRTUAL) ? prop->prototype->offset : prop->offset);
const zend_property_info *root_prop = prop->prototype;
if (UNEXPECTED(root_prop->flags & ZEND_ACC_VIRTUAL)) {
/* Prototype is virtual, we need to manually hunt down the first backed property. */
root_prop = prop;
while (true) {
zend_class_entry *parent_ce = root_prop->ce->parent;
if (!parent_ce) { break; }
zend_property_info *parent_prop = zend_hash_find_ptr(&parent_ce->properties_info, key);
if (!parent_prop
|| parent_prop->prototype != prop->prototype
|| (parent_prop->flags & ZEND_ACC_VIRTUAL)) {
break;
}
root_prop = parent_prop;
}
}
uint32_t prop_table_offset = OBJ_PROP_TO_NUM(root_prop->offset);
table[prop_table_offset] = prop;
}
} ZEND_HASH_FOREACH_END();
Expand Down
Loading