diff --git a/src/Type/ExponentiateHelper.php b/src/Type/ExponentiateHelper.php index 2706d525a3..9b2c3a6581 100644 --- a/src/Type/ExponentiateHelper.php +++ b/src/Type/ExponentiateHelper.php @@ -4,6 +4,7 @@ use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; +use Throwable; use function is_float; use function is_int; use function pow; @@ -85,9 +86,15 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ $max = null; if ($exponent->getMin() !== null) { $min = self::pow($base->getValue(), $exponent->getMin()); + if ($min === null) { + return null; + } } if ($exponent->getMax() !== null) { $max = self::pow($base->getValue(), $exponent->getMax()); + if ($max === null) { + return null; + } } if (!is_float($min) && !is_float($max)) { @@ -97,6 +104,11 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ if ($exponent instanceof ConstantScalarType) { $result = self::pow($base->getValue(), $exponent->getValue()); + + if ($result === null) { + return null; + } + if (is_int($result)) { return new ConstantIntegerType($result); } @@ -106,12 +118,13 @@ private static function exponentiateConstantScalar(ConstantScalarType $base, Typ return null; } - /** - * @return float|int - */ - private static function pow(mixed $base, mixed $exp) + private static function pow(mixed $base, mixed $exp): float|int|null { - return pow($base, $exp); + try { + return pow($base, $exp); + } catch (Throwable) { + return null; + } } }