PHP Fatal error: Uncaught ValueError: x(): Argument #1 ($y) must be ... (PHP 8)
A built-in function received a value of the right type but an invalid content.
Uncaught ValueErrorValueError: max(): Argument #1 ($value) must contain at least one elementValueError must be greater thanValueError must be of type Meaning
PHP 8 converted many warnings into ValueError, for example array_combine with different lengths, str_repeat with a negative count, mb_substr with bad encoding or max([]).
Common causes
- Empty array passed to
max()/min() - Negative or zero length/count argument
array_combinewith different sized arrays- Invalid encoding or flag value
⚡ Quick fix
- Validate arguments before calling
- Read the message for the argument number and rule
- Handle empty collections explicitly
Detailed fix by platform
PHP
if ($items) { $m = max($items); }
How to diagnose
- Function — Which?
- Argument — Which number?
- Data — Empty or out of range?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ArgumentCountError Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected
- Attempt to read property "x" on null Laravel/PHP 8: ErrorException: Attempt to read property "name" on null
- DivisionByZeroError Fatal error: Uncaught DivisionByZeroError: Division by zero
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 2 Dec 2026