From 4b42419be4a2593c44bf6bba62c2efce20c63814 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 6 Feb 2026 18:58:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(php):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=E7=A9=BA=E5=90=88=E5=B9=B6=E8=BF=90=E7=AE=97=E7=AC=A6=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在编译器中实现对 Expr_BinaryOp_Coalesce 节点类型的解析 - 添加 parseBinaryOpCoalesce 方法处理空合并运算符逻辑 - 使用 isset 检查左侧表达式并返回相应的三元运算符结构 - 将左侧标识符解析为变量检查表达式,右侧作为默认值 --- src/Php/CompilerBase.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 67d24168..7884f069 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -282,6 +282,8 @@ class CompilerBase extends \PhpAot\Core\Translator return $this->parseBinaryOpGreaterOrEqual($expr); case 'Expr_BinaryOp_Spaceship': return $this->parseBinaryOpSpaceship($expr); + case 'Expr_BinaryOp_Coalesce': + return $this->parseBinaryOpCoalesce($expr); case 'Expr_PreInc': return $this->parsePreInc($expr); case 'Expr_PostInc': @@ -2191,6 +2193,14 @@ class CompilerBase extends \PhpAot\Core\Translator return 'php::compare(' . $left . ', ' . $right . ')'; } + protected function parseBinaryOpCoalesce(Node\Expr\BinaryOp\Coalesce $expr): string + { + $left = $this->parseIdentifier($expr->left); + $right = $this->parseIdentifier($expr->right); + + return $this->parseVarCheckExpr($expr->left, 'isset') . ' ? ' . $left . ' : ' . $right; + } + protected function parseBinaryOpNotIdentical(Node\Expr\BinaryOp $expr): string { return '!(' . $this->parseBinaryOpIdentical($expr) . ')';