feat(php): 添加标准数组赋值解析支持

- 在 CompilerBase 中添加标准数组表达式检查和解析逻辑
- 引入 NodeAbstract 依赖以支持节点抽象操作
- 实现 parseStdArrayAssign 方法处理标准数组赋值操作
- 添加数组维度获取和类型转换功能
- 确保字符串类型无法使用 [] 操作符的错误检查仍然有效
pull/1/head
韩天峰 4 months ago
parent daa5379e46
commit 36be831b83
  1. 3
      src/Php/CompilerBase.php
  2. 8
      src/Php/Parser/StdArrayParser.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);
}

@ -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);

Loading…
Cancel
Save