From 90866a803b03bbd492218ba8aece9c5ff36af4d9 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 9 Apr 2026 10:22:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=BB=B4=E5=BA=A6=E8=B5=8B=E5=80=BC=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 简化了 isArrayDimFetch 条件判断,添加 isVarExpr 验证 - 重构了字符串类型检查逻辑,移除冗余条件判断 - 直接返回 parseAssignArrayDim 调用结果,简化代码流程 - 移除了不必要的变量赋值和条件分支 --- src/Php/CompilerBase.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 930ce710..3eb0d155 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1443,16 +1443,12 @@ class CompilerBase extends \PhpAot\Core\Translator } } elseif ($this->isPropertyFetch($left) and !$left->getAttribute('nativeProperty')) { return $this->parseAssignPropertyFetch($left, $right); - } elseif ($this->isArrayDimFetch($left)) { + } elseif ($this->isArrayDimFetch($left) and $this->isVarExpr($left->var)) { $tmp = $this->parseIdentifier($left->var); - if ($this->isVarExpr($left->var) and $this->getVarType($tmp) === self::TYPE_STR) { - if ($left->dim === null) { - $this->fatalError($left, 'Cannot use [] for strings'); - } - } - if ($this->isVarExpr($left->var) and ($this->isVarExpr($right) or $this->isScalar($right))) { - return $this->parseAssignArrayDim($left, $right); + if ($this->getVarType($tmp) === self::TYPE_STR and $left->dim === null) { + $this->fatalError($left, 'Cannot use [] for strings'); } + return $this->parseAssignArrayDim($left, $right); } return $var . ' = ' . $this->convertExprType($expr, $this->detectExprType($left), $this->detectExprType($right));