From 0f6e07252beb9a0180c6e62c0052b14736c1c6b6 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 23 Jun 2026 16:39:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96PHP=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8=E4=B8=AD=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=B2?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=93=8D=E4=BD=9C=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了递归展平函数来处理嵌套的连接表达式 - 将原有的二元操作符处理改为多参数列表处理 - 添加了类型检查逻辑以防止空值连接错误 - 更新了OPcache配置命令以确保扩展正确加载 - 重构了连接操作的字符串转换和参数构建过程 --- bin/opcode.php | 2 +- src/Php/Parser/BinaryOpTrait.php | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/bin/opcode.php b/bin/opcode.php index 3910e434..a43f6619 100755 --- a/bin/opcode.php +++ b/bin/opcode.php @@ -9,4 +9,4 @@ if (!file_exists($file)) { echo "File not found: " . $file . "\n"; exit(1); } -shell_exec("php -d opcache.enable_cli=On -d opcache.opt_debug_level=0x10000 " . $file); \ No newline at end of file +shell_exec("php -d zend_extension=opcache -d opcache.enable_cli=On -d opcache.opt_debug_level=0x10000 " . $file); \ No newline at end of file diff --git a/src/Php/Parser/BinaryOpTrait.php b/src/Php/Parser/BinaryOpTrait.php index bb9fec06..f752e65d 100644 --- a/src/Php/Parser/BinaryOpTrait.php +++ b/src/Php/Parser/BinaryOpTrait.php @@ -142,15 +142,29 @@ trait BinaryOpTrait protected function parseBinaryOpConcat(Expr\BinaryOp\Concat $expr): string { - $left = $this->parseExpr($expr->left); - $right = $this->parseExpr($expr->right); + $items = []; + $this->flattenConcatExpr($expr, $items); + + $argList = []; + foreach ($items as $item) { + $type = $this->detectTypeOfExpr($item); + if ($type === self::TYPE_VOID) { + $this->fatalError($expr, 'Cannot concat void'); + } + $argList[] = $this->convertExprToStringByType($this->parseExpr($item), $type); + } - $leftType = $this->detectTypeOfExpr($expr->left); - $rightType = $this->detectTypeOfExpr($expr->right); - if ($leftType === self::TYPE_VOID or $rightType === self::TYPE_VOID) { - $this->fatalError($expr, 'Cannot concat void'); + return Symbol::concat() . '(' . Symbol::argList() . '{' . implode(', ', $argList) . '})'; + } + + private function flattenConcatExpr(NodeAbstract $expr, array &$items): void + { + if ($expr instanceof Expr\BinaryOp\Concat) { + $this->flattenConcatExpr($expr->left, $items); + $this->flattenConcatExpr($expr->right, $items); + } else { + $items[] = $expr; } - return Symbol::concat() . '(' . $this->convertExprToStringByType($left, $leftType) . ', ' . $this->convertExprToStringByType($right, $rightType) . ')'; } protected function parseBinaryOpSmaller(Expr\BinaryOp\Smaller $expr): string