Skip to content

Commit 5a63f7a

Browse files
committed
Fix missing new Foo(...) error in constant expressions
Though first-class callables are now supported in constant expressions, they remain unsupported for the new expression. Fixes phpGH-20113 Closes phpGH-20115
1 parent d8a7018 commit 5a63f7a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0RC3
44

5+
- Core:
6+
. Fixed bug GH-20113 (Missing new Foo(...) error in constant expressions).
7+
(ilutov)
8+
59
- FPM:
610
. Fixed bug GH-19817 (Decode SCRIPT_FILENAME issue in php 8.5).
711
(Jakub Zelenka)
812

9-
1013
- SPL:
1114
. Fixed bug GH-20101 (SplHeap/SplPriorityQueue serialization
1215
exposes INDIRECTs). (nielsdos)

Zend/tests/gh20113.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-20113: new Foo(...) error in constant expressions
3+
--FILE--
4+
<?php
5+
const C = new \stdClass(...);
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot create Closure for new expression in %s on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11468,6 +11468,11 @@ static void zend_compile_const_expr_new(zend_ast **ast_ptr)
1146811468
{
1146911469
zend_ast *class_ast = (*ast_ptr)->child[0];
1147011470
zend_compile_const_expr_class_reference(class_ast);
11471+
11472+
zend_ast *args_ast = (*ast_ptr)->child[1];
11473+
if (args_ast->kind == ZEND_AST_CALLABLE_CONVERT) {
11474+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for new expression");
11475+
}
1147111476
}
1147211477

1147311478
static void zend_compile_const_expr_closure(zend_ast **ast_ptr)

0 commit comments

Comments
 (0)