"Uncaught TypeError: Argument #1 ($x) must be of type X" in PHP — What It Means and How to Fix It
What the PHP error "Uncaught TypeError: Argument #1 ($x) must be of type X" means and how to fix it.
Published November 1, 2026
"Uncaught TypeError: Argument #1 ($x) must be of type X" occurs when a function is called with an argument that doesn't match its declared type (in PHP 7+ with type declarations).
Key points
- PHP's strict typing (when declare(strict_types=1) is used) enforces this exactly; without it, PHP attempts some automatic type coercion first