refactor(php): 更新数组维度获取方法以支持写入操作标识

- 修改 parseArrayDimFetch 方法签名以接受写入布尔参数
- 在 offsetGetIndirect 调用中传递写入操作标识
- 为数组维度访问增加赋值表达式上下文支持
pull/1/head
韩天峰 7 months ago
parent 3bd95121de
commit 6878ecc517
  1. 6
      src/Php/CompilerBase.php

@ -653,7 +653,7 @@ class CompilerBase extends \PhpAot\Core\Translator
case 'Expr_Array': case 'Expr_Array':
return $this->parseArray($expr); return $this->parseArray($expr);
case self::EXPR_ARRAY_DIM_FETCH: case self::EXPR_ARRAY_DIM_FETCH:
return $this->parseArrayDimFetch($expr); return $this->parseArrayDimFetch($expr, $this->inAssignExpr);
case 'Expr_PropertyFetch': case 'Expr_PropertyFetch':
return $this->parsePropertyFetch($expr, $this->inAssignExpr); return $this->parsePropertyFetch($expr, $this->inAssignExpr);
case 'Expr_BinaryOp_ShiftLeft': case 'Expr_BinaryOp_ShiftLeft':
@ -1437,14 +1437,14 @@ class CompilerBase extends \PhpAot\Core\Translator
} }
} }
protected function parseArrayDimFetch($node): string protected function parseArrayDimFetch($node, bool $write): string
{ {
$var = $this->parseIdentifier($node->var); $var = $this->parseIdentifier($node->var);
if ($node->dim === null) { if ($node->dim === null) {
$this->fatalError($node, 'Unsupported operand types: null + array'); $this->fatalError($node, 'Unsupported operand types: null + array');
} }
$dim = $this->parseIdentifier($node->dim); $dim = $this->parseIdentifier($node->dim);
return $var . '.offsetGetIndirect(' . $this->trimBrackets($dim) . ')'; return $var . '.offsetGetIndirect(' . $this->trimBrackets($dim) . ', ' . $this->escapeBool($write) . ')';
} }
protected function parseArrayDimStore($array, $dim, $var): string protected function parseArrayDimStore($array, $dim, $var): string

Loading…
Cancel
Save