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
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬