gmp_powm() Reports More Detail On Modulo-By-Zero
gmp_powm() has thrown a DivisionByZeroError when its $modulus argument is zero since PHP 8.0; this is not new in PHP 8.6. Until PHP 8.6, the exception message was the generic Modulo by zero, giving no clue about which function or argument caused it. In PHP 8.6, the message is prefixed with the function name and the offending argument, becoming gmp_powm(): Argument #3 ($modulus) Modulo by zero.
PHP code
<?php
try {
var_dump(gmp_strval(gmp_powm(2, 3, 0)));
} catch (\DivisionByZeroError $e) {
echo "DivisionByZeroError: ".$e->getMessage()."\n";
}
?>
Before
DivisionByZeroError: Modulo by zero
After
DivisionByZeroError: gmp_powm(): Argument #3 ($modulus) Modulo by zero
PHP version change
This behavior changed in 8.6.