com php-src: Fixed bug #70958 (Invalid opcode while using ::class as trait method paramater default value): NEWS Zend/tests/bug70958.phpt
Zend/zend_compile.c
| From: | Xinchen Hui | Date: | Mon, 23 Nov 2015 10:29:59 +0000 |
| Subject: | com php-src: Fixed bug #70958 (Invalid opcode while using ::class as trait method paramater default value): NEWS Zend/tests/bug70958.phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89967@lists.php.net to get a copy of this message | ||
Commit: a2b85ddecf666281717e50246950fd6d153bb0a8
Author: Xinchen Hui <laruence@gmail.com> Mon, 23 Nov 2015 18:29:59 +0800
Parents: ab17840d33354cc32d24c88d3e401d7b0869c996
Branches: PHP-5.6 PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a2b85ddecf666281717e50246950fd6d153bb0a8
Log:
Fixed bug #70958 (Invalid opcode while using ::class as trait method paramater default value)
Bugs:
https://bugs.php.net/70958
Changed paths:
M NEWS
A Zend/tests/bug70958.phpt
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index 27c215b..b2b4541 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP NEWS
?? ??? 2015, PHP 5.6.17
- Core:
+ . Fixed bug #70958 (Invalid opcode while using ::class as trait method
+ paramater default value). (Laruence)
. Fixed bug #70957 (self::class can not be resolved with reflection for
abstract class). (Laruence)
. Fixed bug #70944 (try{ } finally{} can create infinite chains of
diff --git a/Zend/tests/bug70958.phpt b/Zend/tests/bug70958.phpt
new file mode 100644
index 0000000..b00d7ae
--- /dev/null
+++ b/Zend/tests/bug70958.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #70958 (Invalid opcode while using ::class as trait method paramater default value)
+--FILE--
+<?php
+trait Foo
+{
+ function bar($a = self::class) {
+ var_dump($a);
+ }
+}
+
+class B {
+ use Foo;
+}
+
+$b = new B;
+
+$b->bar();
+?>
+--EXPECT--
+string(1) "B"
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 03c2f5a..da1d392 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2215,9 +2215,15 @@ void zend_do_resolve_class_name(znode *result, znode *class_name, int
is_static
zend_error_noreturn(E_COMPILE_ERROR, "Cannot access self::class when no class scope is
active");
}
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
+ zval_dtor(&class_name->u.constant);
constant_name.op_type = IS_CONST;
- ZVAL_STRINGL(&constant_name.u.constant, "class", sizeof("class")-1, 1);
- zend_do_fetch_constant(result, class_name, &constant_name, ZEND_RT, 1 TSRMLS_CC);
+ ZVAL_STRINGL(&constant_name.u.constant, "__CLASS__",
sizeof("__CLASS__")-1, 1);
+ if (is_static) {
+ *result = constant_name;
+ result->u.constant.type = IS_CONSTANT;
+ } else {
+ zend_do_fetch_constant(result, NULL, &constant_name, ZEND_RT, 1 TSRMLS_CC);
+ }
break;
}
zval_dtor(&class_name->u.constant);