]> granicus.if.org Git - php/commitdiff
Fixup trait methods even if no traits are used
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 5 Nov 2020 12:15:32 +0000 (13:15 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 5 Nov 2020 12:15:32 +0000 (13:15 +0100)
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.

ext/opcache/ZendAccelerator.c
ext/opcache/tests/preload_trait_multiple_fixup.inc
ext/opcache/tests/preload_trait_multiple_fixup.phpt

index a3c079d0f0c46616bf82a1252055e364037cd016..7eee9819cee622c6bc10ec3d4683ce8c2bfbb531 100644 (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();
 
index 5ccb1237a3b028a20dc0cef5279323798069c693..c6c202372547faf490281e098d730782842315e2 100644 (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 {}
index a63458ecc90bf198391cd5a6b1cec603935175ff..dbee2595c219330b4e631afbe39879c6aabe0dd6 100644 (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