com php-src: Fix scope_is_known() for class const ants: Zend/tests/bug69676.phpt Zend/zend_co mpile.c
| From: | Nikita Popov | Date: | Thu, 21 May 2015 19:07:05 +0000 |
| Subject: | com php-src: Fix scope_is_known() for class const ants: Zend/tests/bug69676.phpt Zend/zend_co mpile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86863@lists.php.net to get a copy of this message | ||
Commit: 3dba00bc31eb92ef1187f6dd78f2c7bb3c003710
Author: Nikita Popov <nikic@php.net> Thu, 21 May 2015 21:07:05 +0200
Parents: f186d4b8b19981efd61f629a856e7bdf6ea50155
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3dba00bc31eb92ef1187f6dd78f2c7bb3c003710
Log:
Fix scope_is_known() for class constants
Here the active_op_array is still the surrounding file, but we
do know the scope.
Changed paths:
A Zend/tests/bug69676.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/bug69676.phpt b/Zend/tests/bug69676.phpt
new file mode 100644
index 0000000..54b9d40
--- /dev/null
+++ b/Zend/tests/bug69676.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #69676: Resolution of self::FOO in class constants not correct
+--FILE--
+<?php
+class A {
+ const myConst = "const in A";
+ const myDynConst = self::myConst;
+}
+
+class B extends A {
+ const myConst = "const in B";
+}
+
+var_dump(B::myDynConst);
+var_dump(A::myDynConst);
+?>
+--EXPECT--
+string(10) "const in A"
+string(10) "const in A"
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 78f8ae3..5647523 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -1325,14 +1325,10 @@ static inline zend_bool zend_is_scope_known() /* {{{ */
return 0;
}
- if (!CG(active_op_array)->function_name) {
- /* A file/eval will be run in the including/eval'ing scope */
- return 0;
- }
-
if (!CG(active_class_entry)) {
- /* Not being in a scope is a known scope */
- return 1;
+ /* The scope is known if we're in a free function (no scope), but not if we're in
+ * a file/eval (which inherits including/eval'ing scope). */
+ return CG(active_op_array)->function_name != NULL;
}
/* For traits self etc refers to the using class, not the trait itself */