Skip to content

Commit 03094c7

Browse files
committed
Merge branch 'PHP-7.3'
2 parents b8e9f30 + 1ed2066 commit 03094c7

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Use of self::class inside a constant in an unknown scope
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public function foobar() {
8+
eval("
9+
const FOO = self::class;
10+
var_dump(FOO);
11+
");
12+
}
13+
}
14+
(new Test)->foobar();
15+
16+
// This should error, but doesn't
17+
const BAR = self::class;
18+
var_dump(BAR);
19+
20+
?>
21+
--EXPECT--
22+
string(4) "Test"
23+
string(0) ""

Zend/zend_compile.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_a
13881388

13891389
switch (fetch_type) {
13901390
case ZEND_FETCH_CLASS_SELF:
1391-
if (constant || (CG(active_class_entry) && zend_is_scope_known())) {
1391+
if (CG(active_class_entry) && zend_is_scope_known()) {
13921392
ZVAL_STR_COPY(zv, CG(active_class_entry)->name);
13931393
} else {
13941394
ZVAL_NULL(zv);
@@ -8002,9 +8002,7 @@ void zend_compile_const_expr_magic_const(zend_ast **ast_ptr) /* {{{ */
80028002
zend_ast *ast = *ast_ptr;
80038003

80048004
/* Other cases already resolved by constant folding */
8005-
ZEND_ASSERT(ast->attr == T_CLASS_C &&
8006-
CG(active_class_entry) &&
8007-
(CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0);
8005+
ZEND_ASSERT(ast->attr == T_CLASS_C);
80088006

80098007
zend_ast_destroy(ast);
80108008
*ast_ptr = zend_ast_create(ZEND_AST_CONSTANT_CLASS);

0 commit comments

Comments
 (0)