Skip to content

Commit 5698766

Browse files
committed
Test that anon classes are not supported
And provide a better error message for this case.
1 parent a353b68 commit 5698766

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
New with anonymous class is not supported in constant expressions
3+
--FILE--
4+
<?php
5+
6+
const X = new class {};
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Cannot use anonymous class in constant expression in %s on line %d

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9436,6 +9436,10 @@ void zend_compile_const_expr_magic_const(zend_ast **ast_ptr) /* {{{ */
94369436
static void zend_compile_const_expr_new(zend_ast **ast_ptr)
94379437
{
94389438
zend_ast *class_ast = (*ast_ptr)->child[0];
9439+
if (class_ast->kind == ZEND_AST_CLASS) {
9440+
zend_error_noreturn(E_COMPILE_ERROR,
9441+
"Cannot use anonymous class in constant expression");
9442+
}
94399443
if (class_ast->kind != ZEND_AST_ZVAL) {
94409444
zend_error_noreturn(E_COMPILE_ERROR,
94419445
"Cannot use dynamic class name in constant expression");

0 commit comments

Comments
 (0)