Uncaught ValueError PHP Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

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.

Exact message you may see Uncaught ValueErrorValueError: max(): Argument #1 ($value) must contain at least one elementValueError must be greater thanValueError must be of type
Seen on: PHP

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_combine with different sized arrays
  • Invalid encoding or flag value

⚡ Quick fix

  1. Validate arguments before calling
  2. Read the message for the argument number and rule
  3. Handle empty collections explicitly

Detailed fix by platform

PHP

  1. if ($items) { $m = max($items); }

How to diagnose

  1. Function — Which?
  2. Argument — Which number?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ArgumentCountError — Fatal error: Uncaught ArgumentCountError: Too few arguments to function foo(), 1 passed and exactly 2 expected (PHP)ArgumentCountErrorAttempt to read property "x" on null — Laravel/PHP 8: ErrorException: Attempt to read property "name" on null (Laravel)Attempt to read prope…DivisionByZeroError — Fatal error: Uncaught DivisionByZeroError: Division by zero (PHP)DivisionByZeroErrorFastCGI sent in stderr: PHP message — Nginx: [error] FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect()" while reading response header from upstream (Nginx / Apache)FastCGI sent in stder…rsync error: some files/attrs were not transferred (code 23) — rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) (Linux)rsync error: some fil…TypeError — Fatal error: Uncaught TypeError: foo(): Argument #1 ($x) must be of type int, string given (PHP)TypeErrorTypeError: Argument #1 must be of type X, Y given — Laravel/PHP: TypeError: App\Services\Mailer::send(): Argument #1 ($user) must be of type App\Models\User, null given (Laravel)TypeError: Argument #…Undefined array key — Laravel/PHP 8: ErrorException: Undefined array key "name" (PHP 8) / Undefined index: name (PHP 7) (Laravel)Undefined array keyUncaught …

Explore the map of this error Full error map →

🧠 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.