Skip to content

Commit 3dba00b

Browse files
committed
Fix scope_is_known() for class constants
Here the active_op_array is still the surrounding file, but we do know the scope.
1 parent f186d4b commit 3dba00b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Zend/tests/bug69676.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #69676: Resolution of self::FOO in class constants not correct
3+
--FILE--
4+
<?php
5+
class A {
6+
const myConst = "const in A";
7+
const myDynConst = self::myConst;
8+
}
9+
10+
class B extends A {
11+
const myConst = "const in B";
12+
}
13+
14+
var_dump(B::myDynConst);
15+
var_dump(A::myDynConst);
16+
?>
17+
--EXPECT--
18+
string(10) "const in A"
19+
string(10) "const in A"

Zend/zend_compile.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,14 +1325,10 @@ static inline zend_bool zend_is_scope_known() /* {{{ */
13251325
return 0;
13261326
}
13271327

1328-
if (!CG(active_op_array)->function_name) {
1329-
/* A file/eval will be run in the including/eval'ing scope */
1330-
return 0;
1331-
}
1332-
13331328
if (!CG(active_class_entry)) {
1334-
/* Not being in a scope is a known scope */
1335-
return 1;
1329+
/* The scope is known if we're in a free function (no scope), but not if we're in
1330+
* a file/eval (which inherits including/eval'ing scope). */
1331+
return CG(active_op_array)->function_name != NULL;
13361332
}
13371333

13381334
/* For traits self etc refers to the using class, not the trait itself */

0 commit comments

Comments
 (0)