From 72cf8e7166ed8b1d05f16b6963bb9545f73e4684 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Sat, 20 Jun 2026 21:13:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96=E9=9B=B6?= =?UTF-8?q?=E5=80=BC=E5=AD=97=E9=9D=A2=E9=87=8F=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除多余的变量赋值,直接返回表达式结果 - 统一数值比较操作符的一致性 - 为字符串数值转换添加括号以提高可读性 - 新增对常量和类常量表达式的零值检测支持 - 简化函数中的重复返回语句结构 --- src/Php/CompilerBase.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index a17adf3c..0607cabb 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1232,21 +1232,20 @@ class CompilerBase extends \PhpAot\Core\Translator protected function isZeroLiteral(NodeAbstract $expr): bool { if ($expr instanceof Node\Scalar\Int_) { - $result = $expr->value === 0; - return $result; + return $expr->value === 0; } if ($expr instanceof Node\Scalar\Float_) { - $result = $expr->value == 0.0; - return $result; + return $expr->value == 0.0; } if ($expr instanceof Expr\UnaryMinus || $expr instanceof Expr\UnaryPlus) { - $result = $this->isZeroLiteral($expr->expr); - return $result; + return $this->isZeroLiteral($expr->expr); } if ($expr instanceof Node\Scalar\String_) { $value = trim($expr->value); - $result = $value !== '' && is_numeric($value) && (float) $value == 0.0; - return $result; + return $value !== '' && is_numeric($value) && (float)$value == 0.0; + } + if ($expr instanceof Node\Expr\ConstFetch or $expr instanceof Node\Expr\ClassConstFetch) { + return in_array($this->parseExpr($expr), ['0L', '0LL']); } return false; }