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