PHP ArithmeticError
介绍
ArithmeticError类是从Error类继承的。在执行某些数学运算时可能会发生此类错误。一种这样的情况是尝试执行负量的按位移位操作。当调用 intdiv()函数导致值超出整数的合法范围时,也会引发此错误。
ArithmeticError示例
在下面的示例中,尝试将二进制移位运算符与负操作数一起使用。这导致ArithmeticError。
示例
<?php
try {
$a = 10;
$b = -3;
$result = $a << $b;
}
catch (ArithmeticError $e) {
echo $e->getMessage();
}
?>输出结果
这将产生以下结果-
Bit shift by negative number
如果对 intdiv()函数的调用导致无效的整数,则会引发ArithmeticError。如下例所示,PHP(PHP_INT_MIN)中允许的最小整数不能除以-1
示例
<?php
try {
$a = PHP_INT_MIN;
$b = -1;
$result = intdiv($a, $b);
echo $result;
}
catch (ArithmeticError $e) {
echo $e->getMessage();
}
?>输出结果
这将产生以下结果-
Division of PHP_INT_MIN by -1 is not an integer
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短