- 新增 array-merge-unpack.phpt 测试文件
- 实现 Dg 类用于测试数组合并展开功能
- 添加 f1 方法测试 array_merge(...array_map('array_values', $this->r))
- 添加 f2 方法测试双重 foreach 循环展开
- 实现 chk 方法验证两种方法的结果一致性
- 添加 main 函数执行测试用例
fix(optimizer): 修复函数调用优化器对命名参数和展开参数的处理
- 在 dispatchFuncCall 方法中添加参数检查逻辑
- 检测到命名参数或 unpack 展开参数时返回 false
- 避免静态优化路径处理需要运行时解析的参数
- 确保命名参数和展开语法正确回退到动态调用
pull/3/head
parent
e55da7297d
commit
b8247d4cc7
3 changed files with 76 additions and 0 deletions
@ -0,0 +1,69 @@ |
|||||||
|
--TEST-- |
||||||
|
array merge unpack |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
class Dg { |
||||||
|
private int $c; |
||||||
|
private array $r; |
||||||
|
|
||||||
|
public function __construct(int $c = 3) { |
||||||
|
$this->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 |
||||||
Loading…
Reference in new issue