# Fatal error: Uncaught DivisionByZeroError: Division by zero

**Code:** `DivisionByZeroError` · **Category:** PHP · **Seen on:** PHP

Code divided by zero (or used modulo by zero) — PHP 8 throws instead of warning.

## 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

1. Guard the divisor: `$total > 0 ? $sum / $total : 0`
2. Use `fdiv()` to get INF/NAN instead of an exception
3. Validate numeric input

## Detailed fix by platform

### PHP

1. `$avg = $count ? $sum / $count : 0;`

## How to diagnose

1. **Expression** — Which division?
2. **Data** — Why is the divisor 0?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/php/division-by-zero-error)
