diff --git a/.gitignore b/.gitignore index 428ca671..92110594 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /tmp /examples/wordpress /.php-cs-fixer.cache +*.o \ No newline at end of file diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 6de91202..375cac9f 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -777,11 +777,16 @@ class Translator extends \PhpAot\Core\Translator return filter_var($str, FILTER_VALIDATE_INT); } - private function isCoreFunction(string $fname) + private function isCoreFunction(string $fname): bool { return array_key_exists($fname, $this->definedFunctions); } + private function isAssignOpConcat(string $op): bool + { + return $op === '.='; + } + /** * 尽可能转为数字,优先级 浮点 > 整数 > 字符串 */ @@ -1160,7 +1165,12 @@ class Translator extends \PhpAot\Core\Translator $leftExprType = $node->var->getType(); if ($leftExprType === self::EXPR_VARIABLE) { $type = $this->detectVarType($node->var); - return $var . ' ' . $op . ' ' . $this->convertExprType($expr, $type, $this->detectExprType($node->expr)); + $rightExprStr = $this->convertExprType($expr, $type, $this->detectExprType($node->expr)); + if ($this->isAssignOpConcat($op)) { + return $var . '.append(' . $rightExprStr . ')'; + } else { + return $var . ' ' . $op . ' ' . $rightExprStr; + } } elseif ($leftExprType === self::EXPR_ARRAY_DIM_FETCH) { /** * $count[$r] -= 1;