diff --git a/src/Php/Optimizer/FuncCallOptimizer.php b/src/Php/Optimizer/FuncCallOptimizer.php index f04e1f5d..5cdfbf11 100644 --- a/src/Php/Optimizer/FuncCallOptimizer.php +++ b/src/Php/Optimizer/FuncCallOptimizer.php @@ -225,6 +225,13 @@ trait FuncCallOptimizer protected function dispatchFuncCall(string $name, Node\Expr\FuncCall $expr, array $config): string|false { + // 命名参数 / unpack(...)展开需要运行时处理,回退到动态调用路径 + foreach ($expr->args as $arg) { + if ($arg->name !== null || $arg->unpack) { + return false; + } + } + $target = $config['target'] ?? null; if ($target === null) { $target = 'php::fn::' . $name; diff --git a/tests/aot/array/array-merge-unpack.phpt b/tests/aot/array/array-merge-unpack.phpt new file mode 100644 index 00000000..7d2d2a82 --- /dev/null +++ b/tests/aot/array/array-merge-unpack.phpt @@ -0,0 +1,69 @@ +--TEST-- +array merge unpack +--FILE-- +c = $c; + $this->r = []; + } + + public function g(): self { + for ($i = 0; $i < $this->c; $i++) { + $this->r[] = [ + 'bid' => time(), + 'ct' => 1, + 'cid' => random_int(1e8, 2147483647), + 'cp' => strtoupper(substr(bin2hex(random_bytes(8)), 0, 12)), + 'crt' => date('Y-m-d H:i:s'), + 'mem' => '', + ]; + } + return $this; + } + //array_merge + public function f1(): array { + return array_merge(...array_map('array_values', $this->r)); + } + //双重 foreach + public function f2(): array { + $res = []; + foreach ($this->r as $row) { + foreach ($row as $v) { + $res[] = $v; + } + } + return $res; + } + + public function chk(): void { + $exp = $this->c * count($this->r[0]); + $spr = count($this->f1()); + $loo = count($this->f2()); + + echo "Rows: {$this->c}\n"; + echo "Cols: " . count($this->r[0]) . "\n"; + echo "Exp : {$exp}\n"; + echo "Spr : {$spr}\n"; + echo "Loo : {$loo}\n\n"; + echo ($spr === $exp && $loo === $exp) ? "PASS" : "FAIL"; + echo "\n\n"; + } +} + +function main(): void +{ + (new Dg(3))->g()->chk(); +} +?> +--EXPECT-- +Rows: 3 +Cols: 6 +Exp : 18 +Spr : 18 +Loo : 18 + +PASS diff --git a/tests/aot/arrays/list-nested.phpt b/tests/aot/array/list-nested.phpt similarity index 100% rename from tests/aot/arrays/list-nested.phpt rename to tests/aot/array/list-nested.phpt