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.
--- /dev/null
+--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) ""
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);
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;