Skip to content

Commit 2effbfd

Browse files
committed
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.
1 parent 33969c2 commit 2effbfd

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,16 +4190,12 @@ static int preload_optimize(zend_persistent_script *script)
41904190
}
41914191

41924192
ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) {
4193-
if (ce->num_traits) {
4194-
preload_fix_trait_methods(ce);
4195-
}
4193+
preload_fix_trait_methods(ce);
41964194
} ZEND_HASH_FOREACH_END();
41974195

41984196
ZEND_HASH_FOREACH_PTR(preload_scripts, script) {
41994197
ZEND_HASH_FOREACH_PTR(&script->script.class_table, ce) {
4200-
if (ce->num_traits) {
4201-
preload_fix_trait_methods(ce);
4202-
}
4198+
preload_fix_trait_methods(ce);
42034199
} ZEND_HASH_FOREACH_END();
42044200
} ZEND_HASH_FOREACH_END();
42054201

ext/opcache/tests/preload_trait_multiple_fixup.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@ class C1 {
1717
class C2 extends C1 {
1818
use T2;
1919
}
20+
21+
trait T3 {
22+
public function method() {
23+
// Prevent trivial inheritance.
24+
static $x;
25+
// Needs to be optimized somehow.
26+
$str = "Foo";
27+
echo "$str\n";
28+
}
29+
}
30+
class C3 {
31+
use T3;
32+
}
33+
class C4 extends C3 {}

ext/opcache/tests/preload_trait_multiple_fixup.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows
1313
--FILE--
1414
<?php
1515
(new C2)->method();
16+
(new C4)->method();
1617
?>
1718
--EXPECT--
1819
Foo
20+
Foo

0 commit comments

Comments
 (0)