From 8165e72614bafa872b5e4dd7380243fff0fbb312 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Wed, 7 Jan 2026 15:39:22 +0100 Subject: [PATCH 1/3] Introduce zend_ast_call_get_args() --- Zend/zend_ast.c | 47 +++++++++++++++++++++++++---------------------- Zend/zend_ast.h | 2 ++ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index 2cd2ab40b0497..ab816d03aac3b 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1139,19 +1139,22 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner( { zend_function *fptr; zend_class_entry *called_scope = NULL; + + zend_ast *args_ast = zend_ast_call_get_args(ast); + ZEND_ASSERT(args_ast && 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"); + return FAILURE; + } + 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]; - - 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"); - return FAILURE; - } - fptr = ZEND_MAP_PTR_GET(fcc_ast->fptr); if (!fptr) { @@ -1176,17 +1179,6 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner( break; } case ZEND_AST_STATIC_CALL: { - ZEND_ASSERT(ast->child[2]->kind == ZEND_AST_CALLABLE_CONVERT); - zend_ast_fcc *fcc_ast = (zend_ast_fcc*)ast->child[2]; - - 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"); - return FAILURE; - } - zend_class_entry *ce = zend_ast_fetch_class(ast->child[0], scope); if (!ce) { return FAILURE; @@ -3083,3 +3075,14 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr) return ast; } + +zend_ast * ZEND_FASTCALL zend_ast_call_get_args(zend_ast *ast) +{ + if (ast->kind == ZEND_AST_CALL) { + return ast->child[1]; + } else if (ast->kind == ZEND_AST_STATIC_CALL || ast->kind == ZEND_AST_METHOD_CALL) { + return ast->child[2]; + } + + return NULL; +} diff --git a/Zend/zend_ast.h b/Zend/zend_ast.h index 1c6d6f82fadf8..c212cd8367a87 100644 --- a/Zend/zend_ast.h +++ b/Zend/zend_ast.h @@ -440,4 +440,6 @@ static zend_always_inline zend_ast *zend_ast_list_rtrim(zend_ast *ast) { zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr); +zend_ast * ZEND_FASTCALL zend_ast_call_get_args(zend_ast *ast); + #endif From 79d4e841018ec51cdd63ef63e1cb07fadd56f472 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Wed, 7 Jan 2026 18:57:33 +0100 Subject: [PATCH 2/3] Review --- Zend/zend_ast.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Zend/zend_ast.c b/Zend/zend_ast.c index ab816d03aac3b..e0a68a73bdf27 100644 --- a/Zend/zend_ast.c +++ b/Zend/zend_ast.c @@ -1141,7 +1141,7 @@ static zend_result ZEND_FASTCALL zend_ast_evaluate_inner( zend_class_entry *called_scope = NULL; zend_ast *args_ast = zend_ast_call_get_args(ast); - ZEND_ASSERT(args_ast && args_ast->kind == ZEND_AST_CALLABLE_CONVERT); + ZEND_ASSERT(args_ast->kind == ZEND_AST_CALLABLE_CONVERT); zend_ast_fcc *fcc_ast = (zend_ast_fcc*)args_ast; @@ -3084,5 +3084,6 @@ zend_ast * ZEND_FASTCALL zend_ast_call_get_args(zend_ast *ast) return ast->child[2]; } + ZEND_UNREACHABLE(); return NULL; } From 1514a6b97bf6e59d4b8dbbdf94e8850692fe2ed9 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Thu, 8 Jan 2026 10:57:00 +0100 Subject: [PATCH 3/3] UPGRADING.INTERNALS --- UPGRADING.INTERNALS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 22b9e6f660cb1..748549e085b88 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -52,6 +52,8 @@ PHP 8.6 INTERNALS UPGRADE NOTES . zend_function.arg_info is now always a zend_arg_info*. Before, it was a zend_internal_arg_info on internal functions, unless the ZEND_ACC_USER_ARG_INFO flag was set. + . Added zend_ast_call_get_args() to fetch the argument node from any call + node. ======================== 2. Build system changes