Skip to content

Commit 6b110b1

Browse files
committed
Fixed bug #77643
Resolve property initializers against the correct class, even when parent slots are reused.
1 parent 0989b70 commit 6b110b1

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,23 +3414,16 @@ static void preload_link(void)
34143414
}
34153415
} ZEND_HASH_FOREACH_END();
34163416
if (ce->default_properties_count) {
3417-
zend_class_entry *pce = ce;
3418-
3419-
val = ce->default_properties_table + ce->default_properties_count - 1;
3420-
do {
3421-
uint32_t count = pce->parent ? pce->default_properties_count - pce->parent->default_properties_count : pce->default_properties_count;
3422-
3423-
while (count) {
3424-
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
3425-
if (UNEXPECTED(zval_update_constant_ex(val, pce) != SUCCESS)) {
3426-
ok = 0;
3427-
}
3417+
uint32_t i;
3418+
for (i = 0; i < ce->default_properties_count; i++) {
3419+
val = &ce->default_properties_table[i];
3420+
if (Z_TYPE_P(val) == IS_CONSTANT_AST) {
3421+
zend_property_info *prop = ce->properties_info_table[i];
3422+
if (UNEXPECTED(zval_update_constant_ex(val, prop->ce) != SUCCESS)) {
3423+
ok = 0;
34283424
}
3429-
val--;
3430-
count--;
34313425
}
3432-
pce = pce->parent;
3433-
} while (pce && pce-> default_properties_count);
3426+
}
34343427
}
34353428
if (ce->default_static_members_count) {
34363429
uint32_t count = ce->parent ? ce->default_static_members_count - ce->parent->default_static_members_count : ce->default_static_members_count;

ext/opcache/tests/preload_010.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Initializer of overwritten property should be resolved against the correct class
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_overwritten_prop_init.inc
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
var_dump((new Bar)->prop);
13+
?>
14+
--EXPECT--
15+
int(42)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
class Foo {
4+
public $prop;
5+
}
6+
7+
class Bar extends Foo {
8+
public $prop = self::FOOBAR;
9+
const FOOBAR = 42;
10+
}

0 commit comments

Comments
 (0)