com php-src: Fix __METHOD__ in functions nested into methods: Zend/tests/nested_method_and_funct ion.phpt Zend/zend_compile.c
| From: | Bob Weinand | Date: | Tue, 14 Jul 2015 00:37:35 +0000 |
| Subject: | com php-src: Fix __METHOD__ in functions nested into methods: Zend/tests/nested_method_and_funct ion.phpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87977@lists.php.net to get a copy of this message | ||
Commit: 1003d01f3aa65e1e63a248bc67c2f36538561b35
Author: Bob Weinand <bobwei9@hotmail.com> Tue, 14 Jul 2015 02:37:35 +0200
Parents: 07c425cc290ccea8cf4ae49148b8e26e9024692f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1003d01f3aa65e1e63a248bc67c2f36538561b35
Log:
Fix __METHOD__ in functions nested into methods
Changed paths:
A Zend/tests/nested_method_and_function..phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/nested_method_and_function.phpt b/Zend/tests/nested_method_and_function.phpt
new file mode 100644
index 0000000..46d55dd
--- /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--
+<?php
+
+namespace Baz;
+
+class Foo {
+ public static function bar() {
+ function foo() {
+ var_dump(__FUNCTION__);
+ var_dump(__METHOD__);
+ }
+
+ foo();
+
+ var_dump(__FUNCTION__);
+ var_dump(__METHOD__);
+ }
+}
+
+Foo::bar();
+
+?>
+--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 6808eed..4cf2a57 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;
}
/* }}} */