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:
@@ -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();
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user