]> granicus.if.org Git - php/commitdiff
Fix static method arg binding in traits
authorNikita Popov <nikic@php.net>
Thu, 7 Apr 2016 23:48:21 +0000 (01:48 +0200)
committerNikita Popov <nikic@php.net>
Thu, 7 Apr 2016 23:48:21 +0000 (01:48 +0200)
Zend/tests/traits/no_static_arg_binding.phpt [new file with mode: 0644]
ext/opcache/Optimizer/optimize_func_calls.c

diff --git a/Zend/tests/traits/no_static_arg_binding.phpt b/Zend/tests/traits/no_static_arg_binding.phpt
new file mode 100644 (file)
index 0000000..3134cf6
--- /dev/null
@@ -0,0 +1,28 @@
+--TEST--
+Don't statically bind arguments for self:: calls in traits
+--FILE--
+<?php
+
+trait T {
+    public static function method($arg) {
+    }
+    public static function call() {
+        $i = 0;
+        self::method($i);
+        var_dump($i);
+    }
+}
+
+class C {
+    use T;
+
+    public static function method(&$arg) {
+        $arg++;
+    }
+}
+
+C::call();
+
+?>
+--EXPECT--
+int(1)
index 5982df5f516ffd9b69be431e20af775c7c656e25..8af82e41379b39150472ba503bd632c564e61dc9 100644 (file)
@@ -77,6 +77,7 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
                                                zend_string *class_name = Z_STR_P(&ZEND_OP1_LITERAL(opline) + 1);
                                                ce = zend_hash_find_ptr(&ctx->script->class_table, class_name);
                                        } else if (opline->op1_type == IS_UNUSED && op_array->scope
+                                                       && !(op_array->scope->ce_flags & ZEND_ACC_TRAIT)
                                                        && (opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF) {
                                                ce = op_array->scope;
                                        }