1
0
mirror of https://github.com/php/php-src.git synced 2026-04-02 05:32:28 +02:00

Fixup trait methods even if no traits are used

Trait methods might be non-trivially inherited, in which case we
may have to perform fixup in classes that do not directly use any
traits.
This commit is contained in:
Nikita Popov
2020-11-05 13:15:32 +01:00
parent 33969c2252
commit 2effbfd871
3 changed files with 18 additions and 6 deletions

View File

@@ -4190,16 +4190,12 @@ static int preload_optimize(zend_persistent_script *script)
}
ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) {
if (ce->num_traits) {
preload_fix_trait_methods(ce);
}
preload_fix_trait_methods(ce);
} ZEND_HASH_FOREACH_END();
ZEND_HASH_FOREACH_PTR(preload_scripts, script) {
ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) {
if (ce->num_traits) {
preload_fix_trait_methods(ce);
}
preload_fix_trait_methods(ce);
} ZEND_HASH_FOREACH_END();
} ZEND_HASH_FOREACH_END();

View File

@@ -17,3 +17,17 @@ class C1 {
class C2 extends C1 {
use T2;
}
trait T3 {
public function method() {
// Prevent trivial inheritance.
static $x;
// Needs to be optimized somehow.
$str = "Foo";
echo "$str\n";
}
}
class C3 {
use T3;
}
class C4 extends C3 {}

View File

@@ -13,6 +13,8 @@ if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows
--FILE--
<?php
(new C2)->method();
(new C4)->method();
?>
--EXPECT--
Foo
Foo