fix(aot): 修复链式操作中变量访问顺序问题

- 在编译器基础类中反转变量链表顺序
- 确保变量访问按正确顺序执行
- 添加对空值检查的测试用例
- 验证数组元素访问的正确性
pull/1/head
韩天峰 5 months ago
parent a284a9bfaf
commit 52a0205c96
  1. 2
      src/Php/CompilerBase.php
  2. 39
      tests/aot/empty/001.phpt

@ -3705,6 +3705,8 @@ class CompilerBase extends \PhpAot\Core\Translator
$expr = $expr->var;
}
$list = array_reverse($list);
if ($getValue) {
$result = $this->addTmpVar(self::TYPE_VAR);
$node->setAttribute('chainOpResult', $result);

@ -0,0 +1,39 @@
--TEST--
empty()
--FILE--
<?php
class Foo
{
protected $grid;
public $result = 0;
public function __construct(array $grid)
{
$this->grid = $grid;
}
public function bar()
{
var_dump(empty($this->grid));
var_dump(empty($this->grid[0]));
var_dump(empty($this->grid[1][2]));
var_dump(empty($this->grid[1][5]));
}
}
function main()
{
$arr = [
[0, 1, 0, 0],
[1, 1, 1, 0],
];
$o = new Foo($arr);
$o->bar();
}
?>
--EXPECTF--
bool(false)
bool(false)
bool(false)
bool(true)
Loading…
Cancel
Save