diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-04 09:52:04 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-01-04 09:52:04 +0100 |
commit | 41af1e6781386cf540926ba9d1ff59a3402f8e01 (patch) | |
tree | c8b3077d989bead4534bb17c3d8bfb8f60050bac /Zend | |
parent | cb009b12a54c3dbb0e10b79c6ca77db8736d55b9 (diff) | |
download | php-git-41af1e6781386cf540926ba9d1ff59a3402f8e01.tar.gz |
Fix self::class inside constant in global scope
Previously this triggered an assertion failure. The behavior is
not quite correct, in that self::class should generate an exception
if there is no self, but returns an empty string here. Fixing that
would be a bit too intrusive for the 7.2 branch.
Diffstat (limited to 'Zend')
-rw-r--r-- | Zend/tests/self_class_const_in_unknown_scope.phpt | 23 | ||||
-rw-r--r-- | Zend/zend_compile.c | 6 |
2 files changed, 25 insertions, 4 deletions
diff --git a/Zend/tests/self_class_const_in_unknown_scope.phpt b/Zend/tests/self_class_const_in_unknown_scope.phpt new file mode 100644 index 0000000000..240644dea8 --- /dev/null +++ b/Zend/tests/self_class_const_in_unknown_scope.phpt @@ -0,0 +1,23 @@ +--TEST-- +Use of self::class inside a constant in an unknown scope +--FILE-- +<?php + +class Test { + public function foobar() { + eval(" + const FOO = self::class; + var_dump(FOO); + "); + } +} +(new Test)->foobar(); + +// This should error, but doesn't +const BAR = self::class; +var_dump(BAR); + +?> +--EXPECT-- +string(4) "Test" +string(0) "" diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 23c3b99968..d91b656182 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1513,7 +1513,7 @@ static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_a switch (fetch_type) { case ZEND_FETCH_CLASS_SELF: - if (constant || (CG(active_class_entry) && zend_is_scope_known())) { + if (CG(active_class_entry) && zend_is_scope_known()) { ZVAL_STR_COPY(zv, CG(active_class_entry)->name); } else { ZVAL_NULL(zv); @@ -8009,9 +8009,7 @@ void zend_compile_const_expr_magic_const(zend_ast **ast_ptr) /* {{{ */ zend_ast *ast = *ast_ptr; /* Other cases already resolved by constant folding */ - ZEND_ASSERT(ast->attr == T_CLASS_C && - CG(active_class_entry) && - (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0); + ZEND_ASSERT(ast->attr == T_CLASS_C); { zval const_zv; |