1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Resolve property initializers against the correct class, even when
parent slots are reused.
This commit is contained in:
Nikita Popov
2019-02-21 10:59:30 +01:00
parent 0989b70015
commit 6b110b151d
3 changed files with 33 additions and 15 deletions

View File

@@ -3414,23 +3414,16 @@ static void preload_link(void)
}
} ZEND_HASH_FOREACH_END();
if (ce->default_properties_count) {
zend_class_entry *pce = ce;
val = ce->default_properties_table + ce->default_properties_count - 1;
do {
uint32_t count = pce->parent ? pce->default_properties_count - pce->parent->default_properties_count : pce->default_properties_count;
while (count) {
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
if (UNEXPECTED(zval_update_constant_ex(val, pce) != SUCCESS)) {
ok = 0;
}
uint32_t i;
for (i = 0; i < ce->default_properties_count; i++) {
val = &ce->default_properties_table[i];
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
zend_property_info *prop = ce->properties_info_table[i];
if (UNEXPECTED(zval_update_constant_ex(val, prop->ce) != SUCCESS)) {
ok = 0;
}
val--;
count--;
}
pce = pce->parent;
} while (pce && pce-> default_properties_count);
}
}
if (ce->default_static_members_count) {
uint32_t count = ce->parent ? ce->default_static_members_count - ce->parent->default_static_members_count : ce->default_static_members_count;

View File

@@ -0,0 +1,15 @@
--TEST--
Initializer of overwritten property should be resolved against the correct class
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload_overwritten_prop_init.inc
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
var_dump((new Bar)->prop);
?>
--EXPECT--
int(42)

View File

@@ -0,0 +1,10 @@
<?php
class Foo {
public $prop;
}
class Bar extends Foo {
public $prop = self::FOOBAR;
const FOOBAR = 42;
}