Skip to content

Commit

Permalink
Fix scope_is_known() for class constants
Browse files Browse the repository at this point in the history
Here the active_op_array is still the surrounding file, but we
do know the scope.
  • Loading branch information
nikic committed May 21, 2015
1 parent f186d4b commit 3dba00b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 19 additions & 0 deletions 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"
10 changes: 3 additions & 7 deletions Zend/zend_compile.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 3dba00b

Please sign in to comment.