TypeError 🐘 PHP

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

  1. Cast/validate input: (int) $_GET['id']
  2. Make the parameter nullable (?int) if null is valid
  3. Check argument order against the signature

Detailed fix by platform

PHP

  1. PHP 8.1+ also deprecates passing null to non-nullable *internal* parameters (e.g. strlen(null)) — guard with ?? ''

How to diagnose

  1. Argument — Which argument number and expected type?
  2. 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.