From 52a0205c9615c119dd86b9e759baf4b688332a3c Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 7 Apr 2026 14:51:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(aot):=20=E4=BF=AE=E5=A4=8D=E9=93=BE?= =?UTF-8?q?=E5=BC=8F=E6=93=8D=E4=BD=9C=E4=B8=AD=E5=8F=98=E9=87=8F=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E9=A1=BA=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器基础类中反转变量链表顺序 - 确保变量访问按正确顺序执行 - 添加对空值检查的测试用例 - 验证数组元素访问的正确性 --- src/Php/CompilerBase.php | 2 ++ tests/aot/empty/001.phpt | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/aot/empty/001.phpt diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index ed5df308..538c00b3 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -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); diff --git a/tests/aot/empty/001.phpt b/tests/aot/empty/001.phpt new file mode 100644 index 00000000..0a231cb7 --- /dev/null +++ b/tests/aot/empty/001.phpt @@ -0,0 +1,39 @@ +--TEST-- +empty() +--FILE-- +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)