From 3492a4ebe67afac2435458af345bbdc6317d7467 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 5 Jan 2026 16:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20AssignOpConcat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + src/Php/Translator.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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;