mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Fix accidentally inherited default value in overridden virtual properties
Discovered when working on GH-17376.
This commit is contained in:
parent
7a55116f12
commit
e0c69dde02
6 changed files with 67 additions and 4 deletions
|
@ -1478,14 +1478,21 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
|
|||
zend_error_noreturn(E_COMPILE_ERROR, "Access level to %s::$%s must be %s (as in class %s)%s", ZSTR_VAL(ce->name), ZSTR_VAL(key), zend_visibility_string(parent_info->flags), ZSTR_VAL(parent_info->ce->name), (parent_info->flags&ZEND_ACC_PUBLIC) ? "" : " or weaker");
|
||||
}
|
||||
if (!(child_info->flags & ZEND_ACC_STATIC) && !(parent_info->flags & ZEND_ACC_VIRTUAL)) {
|
||||
int parent_num = OBJ_PROP_TO_NUM(parent_info->offset);
|
||||
if (child_info->offset != ZEND_VIRTUAL_PROPERTY_OFFSET) {
|
||||
int parent_num = OBJ_PROP_TO_NUM(parent_info->offset);
|
||||
int child_num = OBJ_PROP_TO_NUM(child_info->offset);
|
||||
|
||||
/* Don't keep default properties in GC (they may be freed by opcache) */
|
||||
zval_ptr_dtor_nogc(&(ce->default_properties_table[parent_num]));
|
||||
ce->default_properties_table[parent_num] = ce->default_properties_table[child_num];
|
||||
ZVAL_UNDEF(&ce->default_properties_table[child_num]);
|
||||
} else {
|
||||
/* Default value was removed in child, remove it from parent too. */
|
||||
if (ZEND_TYPE_IS_SET(child_info->type)) {
|
||||
ZVAL_UNDEF(&ce->default_properties_table[parent_num]);
|
||||
} else {
|
||||
ZVAL_NULL(&ce->default_properties_table[parent_num]);
|
||||
}
|
||||
}
|
||||
|
||||
child_info->offset = parent_info->offset;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue