From: Bob Weinand Date: Tue, 14 Jul 2015 00:37:35 +0000 (+0200) Subject: Fix __METHOD__ in functions nested into methods X-Git-Tag: php-7.1.1RC1~35^2~6^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1003d01f3aa65e1e63a248bc67c2f36538561b35;p=php Fix __METHOD__ in functions nested into methods --- diff --git a/Zend/tests/nested_method_and_function.phpt b/Zend/tests/nested_method_and_function.phpt new file mode 100644 index 0000000000..46d55ddc52 --- /dev/null +++ b/Zend/tests/nested_method_and_function.phpt @@ -0,0 +1,29 @@ +--TEST-- +active_class_entry must be always correct (__METHOD__ should not depend on declaring function ce) +--FILE-- + +--EXPECT-- +string(7) "Baz\foo" +string(7) "Baz\foo" +string(3) "bar" +string(12) "Baz\Foo::bar" diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 6808eedbc6..4cf2a57f75 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -4793,6 +4793,7 @@ 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; @@ -4817,6 +4818,11 @@ 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) { @@ -4852,6 +4858,7 @@ 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; } /* }}} */