From 7e52d51b5bdde4c427eae76bd90a294e8341b25a Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Thu, 18 Jun 2026 10:22:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(php):=20=E8=A7=A3=E5=86=B3=E9=99=A4?= =?UTF-8?q?=E9=9B=B6=E8=BF=90=E7=AE=97=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了对除法和取模运算中零值检测的统一处理 - 当遇到除零或模零运算时抛出致命错误而不是返回NaN - 移除了旧的零除法返回NaN的逻辑 - 统一了除法和取模运算的零值检查条件 --- src/Php/Parser/BinaryOpTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Php/Parser/BinaryOpTrait.php b/src/Php/Parser/BinaryOpTrait.php index efd214ec..9b3ece94 100644 --- a/src/Php/Parser/BinaryOpTrait.php +++ b/src/Php/Parser/BinaryOpTrait.php @@ -121,12 +121,12 @@ trait BinaryOpTrait $leftExpr = $this->convertExprType($leftExpr, $leftType, self::TYPE_FLOAT); } - if ($op === '%' and !($leftType === self::TYPE_INT and $rightType === self::TYPE_INT)) { - return 'php::fn::mod(' . $leftExpr . ', ' . $rightExpr . ')'; + if (($op === '/' or $op === '%') and $this->isZeroLiteral($right)) { + $this->fatalError($right, 'Cannot divide or modulo by zero'); } - if ($op === '/' and $this->isZeroLiteral($right)) { - return self::VALUE_NAN; + if ($op === '%' and !($leftType === self::TYPE_INT and $rightType === self::TYPE_INT)) { + return 'php::fn::mod(' . $leftExpr . ', ' . $rightExpr . ')'; } return '((' . $leftExpr . ') ' . $op . ' (' . $rightExpr . '))';