From 898cbe255369a1e1f9d591874d3a15277d6fcc1f Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 30 Mar 2026 17:02:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=94=AF=E6=8C=81=20func=5Fnum=5F?= =?UTF-8?q?args=20=E5=87=BD=E6=95=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 UNSUPPORTED_FUNCTIONS 列表中移除 func_num_args - 添加 func_num_args 函数的运行时测试用例 - 实现 func_num_args 函数调用优化逻辑 - 支持通过 argInfoList 计算函数参数数量 - 添加对可变参数函数的支持 --- src/Php/Constants.php | 1 - src/Php/FuncCallOptimizer.php | 12 +++++++++++ tests/aot/functions/func_num_args.phpt | 29 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/aot/functions/func_num_args.phpt diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 2fca7b6f..1b41e3de 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -59,7 +59,6 @@ class Constants public const UNSUPPORTED_FUNCTIONS = [ 'compact', 'extract', - 'func_num_args', 'func_get_arg', 'func_get_args', ]; diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index be16620b..c1b330fa 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -56,6 +56,18 @@ trait FuncCallOptimizer if ($name === 'array_key_exists') { return $getArg(1) . '.offsetExists(' . $getArg(0) . ')'; } + if ($name === 'func_get_args') { + + } + if ($name === 'func_num_args') { + $funcDef = $this->functionDef; + foreach ($funcDef->argInfoList as $i => $argInfo) { + if ($argInfo->variadic) { + return '(' . $argInfo->name . '.count() + ' . $i . ')'; + } + } + return count($funcDef->argInfoList); + } if ($name === 'function_exists') { $funcName = $expr->args[0]->value; if ($this->isScalarString($funcName)) { diff --git a/tests/aot/functions/func_num_args.phpt b/tests/aot/functions/func_num_args.phpt new file mode 100644 index 00000000..d0650222 --- /dev/null +++ b/tests/aot/functions/func_num_args.phpt @@ -0,0 +1,29 @@ +--TEST-- +func_num_args +--FILE-- + +--EXPECT-- +int(3) +int(5) +int(6) \ No newline at end of file