From 36be831b830adadbbac501d53350c59e1caa7aac Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 7 May 2026 11:58:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E5=87=86=E6=95=B0=E7=BB=84=E8=B5=8B=E5=80=BC=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CompilerBase 中添加标准数组表达式检查和解析逻辑 - 引入 NodeAbstract 依赖以支持节点抽象操作 - 实现 parseStdArrayAssign 方法处理标准数组赋值操作 - 添加数组维度获取和类型转换功能 - 确保字符串类型无法使用 [] 操作符的错误检查仍然有效 --- src/Php/CompilerBase.php | 3 +++ src/Php/Parser/StdArrayParser.php | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index a814a6d8..2b6798ce 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1589,6 +1589,9 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->getVarType($tmp) === self::TYPE_STR and $left->dim === null) { $this->fatalError($left, 'Cannot use [] for strings'); } + if ($this->isStdArrayExpr($left)) { + return $this->parseStdArrayAssign($left, $right); + } return $this->parseAssignArrayDim($left, $right); } diff --git a/src/Php/Parser/StdArrayParser.php b/src/Php/Parser/StdArrayParser.php index fc0ef340..20de1282 100644 --- a/src/Php/Parser/StdArrayParser.php +++ b/src/Php/Parser/StdArrayParser.php @@ -4,6 +4,7 @@ namespace PhpAot\Php\Parser; use PhpAot\Php\Symbol; use PhpParser\Node\Expr; +use PhpParser\NodeAbstract; trait StdArrayParser { @@ -44,6 +45,13 @@ trait StdArrayParser } } + protected function parseStdArrayAssign(NodeAbstract $left, NodeAbstract $right): string + { + $info = $this->getStdArrayInfo($left); + $arrayDimFetch = $this->parseStdArrayDimFetch($left); + return $arrayDimFetch . ' = ' . $this->convertExprFromType($info['type'], $this->parseExpr($right)); + } + protected function parseStdArrayAssignOp(Expr\AssignOp $expr, string $op): string { $binaryOp = $this->removeAssignOp($op);