Fatal error: Uncaught DivisionByZeroError: Division by zero
Code divided by zero (or used modulo by zero) — PHP 8 throws instead of warning.
Seen on:
PHP
Meaning
PHP 8 converted division by zero from a warning into DivisionByZeroError. Averages, percentages and ratios over empty data are the usual source.
Common causes
- Empty dataset (count is 0) used as a divisor
- User input of 0
- Modulo by zero (
%)
⚡ Quick fix
- Guard the divisor:
$total > 0 ? $sum / $total : 0 - Use
fdiv()to get INF/NAN instead of an exception - Validate numeric input
Detailed fix by platform
PHP
$avg = $count ? $sum / $count : 0;
How to diagnose
- Expression — Which division?
- Data — Why is the divisor 0?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026