From 0a3ce8c503c8cb0b1ac4bc7f71d1e09b406b42ce Mon Sep 17 00:00:00 2001 From: yavon007 Date: Sat, 12 Sep 2026 15:11:28 +0800 Subject: [PATCH 1/2] Fix lost fixed arguments in variadic func_get_args --- phpunit/code/variadic-fixed-arguments.php | 2 ++ phpunit/src/VariadicFixedArgumentsTest.php | 21 ++++++++++++++++++ src/Optimizer/FuncCallOptimizer.php | 2 +- .../func-get-args-fixed-variadic.phpt | 22 +++++++++++++++++++ tests/compiler/functions/func_get_args.phpt | 14 ++++++++---- 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 phpunit/code/variadic-fixed-arguments.php create mode 100644 phpunit/src/VariadicFixedArgumentsTest.php create mode 100644 tests/compiler/functions/func-get-args-fixed-variadic.phpt diff --git a/phpunit/code/variadic-fixed-arguments.php b/phpunit/code/variadic-fixed-arguments.php new file mode 100644 index 00000000..d8e78342 --- /dev/null +++ b/phpunit/code/variadic-fixed-arguments.php @@ -0,0 +1,2 @@ +addFiles([$source]); + $compiler->prepareFile($source); + $code = file_get_contents($compiler->convertFile($source)); + self::assertMatchesRegularExpression( + '/(tmp_var_\d+) = php::Array\{\s*head\s*\};\s*\1\.merge\(tail\);/', + $code, + ); + } +} diff --git a/src/Optimizer/FuncCallOptimizer.php b/src/Optimizer/FuncCallOptimizer.php index 2a28700a..cba6f0bc 100644 --- a/src/Optimizer/FuncCallOptimizer.php +++ b/src/Optimizer/FuncCallOptimizer.php @@ -1367,7 +1367,7 @@ protected function genFuncGetArgs(string $name, Node\Expr\FuncCall $expr, array foreach ($funcDef->argInfoList as $i => $argInfo) { if ($argInfo->variadic) { $tmpVar = $this->addTmpVar(Type::ARRAY); - $this->context->beforeStmtLines[] = $this->genArray($list) . ';'; + $this->context->beforeStmtLines[] = $tmpVar . ' = ' . $this->genArray($list) . ';'; $this->context->beforeStmtLines[] = $tmpVar . '.merge(' . $argInfo->name . ');'; return $tmpVar; } diff --git a/tests/compiler/functions/func-get-args-fixed-variadic.phpt b/tests/compiler/functions/func-get-args-fixed-variadic.phpt new file mode 100644 index 00000000..91da5c27 --- /dev/null +++ b/tests/compiler/functions/func-get-args-fixed-variadic.phpt @@ -0,0 +1,22 @@ +--TEST-- +func_get_args retains fixed parameters before the variadic tail +--FILE-- + int(10) } -array(3) { +array(6) { [0]=> - int(8) + int(1) [1]=> - int(10) + int(3) [2]=> + int(5) + [3]=> + int(8) + [4]=> + int(10) + [5]=> int(12) -} \ No newline at end of file +} From 5828e544789ed3d23b25b46284d33eadf1380aab Mon Sep 17 00:00:00 2001 From: yavon007 Date: Sat, 12 Sep 2026 15:29:15 +0800 Subject: [PATCH 2/2] Fix closing tag in variadic argument PHPT fixture --- tests/compiler/functions/func-get-args-fixed-variadic.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/compiler/functions/func-get-args-fixed-variadic.phpt b/tests/compiler/functions/func-get-args-fixed-variadic.phpt index 91da5c27..f1dd9e3b 100644 --- a/tests/compiler/functions/func-get-args-fixed-variadic.phpt +++ b/tests/compiler/functions/func-get-args-fixed-variadic.phpt @@ -14,6 +14,7 @@ function main(): void { $head = 1; echo json_encode(changedFixed($head,2,3)), ':', $head, "\n"; } +?> --EXPECT-- [1,2,3] [1]