1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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 GH-20113
Closes GH-20115
This commit is contained in:
Ilija Tovilo
2025-10-09 18:22:54 +02:00
parent d8a7018289
commit 5a63f7a54b
3 changed files with 17 additions and 1 deletions

5
NEWS
View File

@@ -2,11 +2,14 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.5.0RC3
- Core:
. Fixed bug GH-20113 (Missing new Foo(...) error in constant expressions).
(ilutov)
- FPM:
. Fixed bug GH-19817 (Decode SCRIPT_FILENAME issue in php 8.5).
(Jakub Zelenka)
- SPL:
. Fixed bug GH-20101 (SplHeap/SplPriorityQueue serialization
exposes INDIRECTs). (nielsdos)

8
Zend/tests/gh20113.phpt Normal file
View File

@@ -0,0 +1,8 @@
--TEST--
GH-20113: new Foo(...) error in constant expressions
--FILE--
<?php
const C = new \stdClass(...);
?>
--EXPECTF--
Fatal error: Cannot create Closure for new expression in %s on line %d

View File

@@ -11468,6 +11468,11 @@ static void zend_compile_const_expr_new(zend_ast **ast_ptr)
{
zend_ast *class_ast = (*ast_ptr)->child[0];
zend_compile_const_expr_class_reference(class_ast);
zend_ast *args_ast = (*ast_ptr)->child[1];
if (args_ast->kind == ZEND_AST_CALLABLE_CONVERT) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for new expression");
}
}
static void zend_compile_const_expr_closure(zend_ast **ast_ptr)