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..f1dd9e3b --- /dev/null +++ b/tests/compiler/functions/func-get-args-fixed-variadic.phpt @@ -0,0 +1,23 @@ +--TEST-- +func_get_args retains fixed parameters before the variadic tail +--FILE-- + +--EXPECT-- +[1,2,3] +[1] +["a","b",3,4] +[1,2] +[7,2,3]:7 diff --git a/tests/compiler/functions/func_get_args.phpt b/tests/compiler/functions/func_get_args.phpt index 6219fc7a..18ec89ee 100644 --- a/tests/compiler/functions/func_get_args.phpt +++ b/tests/compiler/functions/func_get_args.phpt @@ -44,11 +44,17 @@ array(5) { [4]=> 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 +}