Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
PHP DivisionByZeroError
The DivisionByZeroError class is a subclass of ArithmeticError class. This type of error occurs when division operations involve a denominator value of zero. This can also occur when a modulo operator (%) has 0 as the second operand, and the intdiv() function has 0 as its second argument.
Modulo Division by Zero
The modulo operator (%) throws a DivisionByZeroError when the divisor is zero ?
<?php
try {
$a = 10;
$b = 0;
$result = $a % $b;
echo $result;
}
catch (DivisionByZeroError $e) {
echo $e->getMessage();
}
?>
Modulo by zero
Integer Division by Zero
The intdiv() function also raises DivisionByZeroError when the divisor is zero ?
<?php
try {
$a = 10;
$b = 0;
$result = intdiv($a, $b);
echo $result;
}
catch (DivisionByZeroError $e) {
echo $e->getMessage();
}
?>
Division by zero
Float Division by Zero
The division operator (/) with 0 as denominator does not raise an error but produces a warning and returns the PHP constant INF (infinity) ?
<?php
try {
$a = 10;
$b = 0;
$result = $a / $b;
echo $result;
}
catch (DivisionByZeroError $e) {
echo $e->getMessage();
}
?>
INF
Advertisements
