Unsupported operand types 🐘 PHP

Fatal error: Uncaught TypeError: Unsupported operand types: string + int

An arithmetic or array operator was used with incompatible types (PHP 8 is stricter than PHP 7).

Seen on: PHP

Meaning

PHP 8 throws for operations like array + int or string + array. Non-numeric strings in arithmetic throw “Unsupported operand types” or warn “A non-numeric value encountered”.

Common causes

  • Array used in arithmetic
  • null/empty array where a number was expected
  • Non-numeric strings from input

⚡ Quick fix

  1. Cast and validate numbers: (float) $price
  2. Check variables are numbers before arithmetic
  3. Use array_sum() for arrays

Detailed fix by platform

PHP

  1. $total = array_sum(array_map('floatval', $prices));

How to diagnose

  1. Operands — What are the two types?
  2. Source — Where does the non-number come 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.