Commit be82abb58ac for php.net
commit be82abb58ac47cb3c1708b4c1935777a09b410a2
Merge: 417e3d7269a 740d1f57505
Author: Arnaud Le Blanc <arnaud.lb@gmail.com>
Date: Wed Jul 22 09:46:48 2026 +0200
Merge branch 'PHP-8.5'
* PHP-8.5:
Fix const expr support in preloading (#22783)
diff --cc Zend/zend_ast.c
index adcb62a51d1,03ce073808a..1b293c832c9
--- a/Zend/zend_ast.c
+++ b/Zend/zend_ast.c
@@@ -1139,23 -1054,18 +1139,29 @@@ static zend_result ZEND_FASTCALL zend_a
case ZEND_AST_CALL:
case ZEND_AST_STATIC_CALL:
{
+ // Preloading will attempt to resolve constants but objects can't be stored in shm
+ // Aborting here to store the const AST instead
+ if (CG(in_compilation)) {
+ return FAILURE;
+ }
+
zend_function *fptr;
zend_class_entry *called_scope = NULL;
+
+ zend_ast *args_ast = zend_ast_call_get_args(ast);
+ ZEND_ASSERT(args_ast->kind == ZEND_AST_CALLABLE_CONVERT);
+
+ zend_ast_fcc *fcc_ast = (zend_ast_fcc*)args_ast;
+
+ zend_ast_list *args = zend_ast_get_list(fcc_ast->args);
+ ZEND_ASSERT(args->children > 0);
+ if (args->children != 1 || args->child[0]->attr != ZEND_PLACEHOLDER_VARIADIC) {
+ /* TODO: PFAs */
+ zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
+ }
+
switch (ast->kind) {
case ZEND_AST_CALL: {
- ZEND_ASSERT(ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT);
- zend_ast_fcc *fcc_ast = (zend_ast_fcc*)ast->child[1];
fptr = ZEND_MAP_PTR_GET(fcc_ast->fptr);
if (!fptr) {
diff --cc Zend/zend_compile.c
index bb24d73fb24,d8d61ea979e..6a677e71a6b
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@@ -12031,14 -11514,6 +12031,12 @@@ static void zend_compile_const_expr_fcc
zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
}
+ zend_ast_list *args = zend_ast_get_list(((zend_ast_fcc*)*args_ast)->args);
+ if (args->children != 1 || args->child[0]->attr != ZEND_PLACEHOLDER_VARIADIC) {
+ // TODO: PFAs
+ zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
+ }
+
- ZEND_MAP_PTR_NEW(((zend_ast_fcc *)*args_ast)->fptr);
-
switch ((*ast_ptr)->kind) {
case ZEND_AST_CALL: {
zend_ast *name_ast = (*ast_ptr)->child[0];
diff --cc ext/opcache/zend_file_cache.c
index af59b9b2c34,fef6a5a5f42..265d5de4147
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@@ -1308,11 -1303,9 +1308,13 @@@ static void zend_file_cache_unserialize
zend_ast_get_op_array(ast)->op_array = Z_PTR(z);
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
zend_ast_fcc *fcc = (zend_ast_fcc*)ast;
- ZEND_MAP_PTR_NEW(fcc->fptr);
+ if (!script->corrupted) {
+ ZEND_MAP_PTR_NEW(fcc->fptr);
+ }
+ if (!IS_UNSERIALIZED(fcc->args)) {
+ UNSERIALIZE_PTR(fcc->args);
+ zend_file_cache_unserialize_ast(fcc->args, script, buf);
+ }
} else if (zend_ast_is_decl(ast)) {
/* Not implemented. */
ZEND_UNREACHABLE();
diff --cc ext/opcache/zend_persist.c
index c06452e6acf,a4aea9fae65..d3e719dbed7
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@@ -195,7 -197,9 +195,10 @@@ static zend_ast *zend_persist_ast(zend_
node = (zend_ast *) copy;
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
zend_ast_fcc *copy = zend_shared_memdup(ast, sizeof(zend_ast_fcc));
+ if (!ZCG(current_persistent_script)->corrupted) {
+ ZEND_MAP_PTR_NEW(copy->fptr);
+ }
+ copy->args = zend_persist_ast(copy->args);
node = (zend_ast *) copy;
} else if (zend_ast_is_decl(ast)) {
/* Not implemented. */