com php-src: Fix for #70159 - Better magic constants substitution: NEWS Zend/tests/nested_method_and_function.phpt Zend/zend _compile.c
| From: | JulienPauli | Date: | Tue, 28 Jul 2015 14:30:08 +0000 |
| Subject: | com php-src: Fix for #70159 - Better magic constants substitution: NEWS Zend/tests/nested_method_and_function.phpt Zend/zend _compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88202@lists.php.net to get a copy of this message | ||
Commit: a28115ccdb11301a418cc748ef7716a1687cc585
Author: Julien Pauli <jpauli@php.net> Tue, 28 Jul 2015 15:27:58 +0200
Parents: 94e23b29a1666f0733177e15868c60c7807f4095
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a28115ccdb11301a418cc748ef7716a1687cc585
Log:
Fix for #70159 - Better magic constants substitution
Bugs:
https://bugs.php.net/70159
Changed paths:
M NEWS
M Zend/tests/nested_method_and_function.phpt
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index 3d41dd9..6802c79 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP NEWS
06 Aug 2015, PHP 7.0.0 Beta 3
- Core:
+ . Fixed bug #70159 (__CLASS__ is lost in closures). (Julien)
. Fixed bug #70156 (Segfault in zend_find_alias_name). (Laruence)
. Fixed bug #70124 (null ptr deref / seg fault in ZEND_HANDLE_EXCEPTION).
(Laruence)
diff --git a/Zend/tests/nested_method_and_function.phpt b/Zend/tests/nested_method_and_function.phpt
index 46d55dd..19f92ad 100644
--- a/Zend/tests/nested_method_and_function.phpt
+++ b/Zend/tests/nested_method_and_function.phpt
@@ -10,20 +10,30 @@ class Foo {
function foo() {
var_dump(__FUNCTION__);
var_dump(__METHOD__);
+ var_dump(__CLASS__);
}
foo();
var_dump(__FUNCTION__);
var_dump(__METHOD__);
+ var_dump(__CLASS__);
+
+ return function() {var_dump(__FUNCTION__); var_dump(__METHOD__); var_dump(__CLASS__); };
}
}
-Foo::bar();
+$c = Foo::bar();
+$c();
?>
--EXPECT--
string(7) "Baz\foo"
string(7) "Baz\foo"
+string(7) "Baz\Foo"
string(3) "bar"
string(12) "Baz\Foo::bar"
+string(7) "Baz\Foo"
+string(13) "Baz\{closure}"
+string(13) "Baz\{closure}"
+string(7) "Baz\Foo"
\ No newline at end of file
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index b7be2e9..a60a446 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -4797,7 +4797,6 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
zend_bool is_method = decl->kind == ZEND_AST_METHOD;
zend_op_array *orig_op_array = CG(active_op_array);
- zend_class_entry *orig_ce = CG(active_class_entry);
zend_op_array *op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
zend_oparray_context orig_oparray_context;
@@ -4823,10 +4822,6 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
CG(active_op_array) = op_array;
- if (!is_method) {
- CG(active_class_entry) = NULL;
- }
-
zend_oparray_context_begin(&orig_oparray_context);
if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
@@ -4862,7 +4857,6 @@ void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
/* Pop the loop variable stack separator */
zend_stack_del_top(&CG(loop_var_stack));
- CG(active_class_entry) = orig_ce;
CG(active_op_array) = orig_op_array;
}
/* }}} */
@@ -5692,7 +5686,9 @@ static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{
*/
}
break;
case T_METHOD_C:
- if (ce) {
+ if ((op_array && !op_array->scope && op_array->function_name) ||
(op_array->fn_flags & ZEND_ACC_CLOSURE)) {
+ ZVAL_STR_COPY(zv, op_array->function_name);
+ } else if (ce) {
if (op_array && op_array->function_name) {
ZVAL_NEW_STR(zv, zend_concat3(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), "::", 2,
ZSTR_VAL(op_array->function_name), ZSTR_LEN(op_array->function_name)));