Fatal error: Uncaught TypeError: foo(): Argument #1 ($x) must be of type int, string given
A function received a value of the wrong type for a typed parameter.
Seen on:
PHP
Meaning
With type declarations (and especially declare(strict_types=1)), PHP rejects arguments that don’t match. Form input is always a string, so passing $_POST values to int/float parameters is the classic cause.
Common causes
- Request input (strings) passed to int/float/bool parameters
- null passed to a non-nullable parameter
- Wrong argument order
- Library upgrade changed a signature
⚡ Quick fix
- Cast/validate input:
(int) $_GET['id'] - Make the parameter nullable (
?int) if null is valid - Check argument order against the signature
Detailed fix by platform
PHP
- PHP 8.1+ also deprecates passing null to non-nullable *internal* parameters (e.g.
strlen(null)) — guard with?? ''
How to diagnose
- Argument — Which argument number and expected type?
- Value — What type was passed and where from?
🧠 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