Implicit float to int 🐘 PHP

Deprecated: Implicit conversion from float 2.5 to int loses precision

PHP 8.1+ warns when a float with a fractional part is silently converted to int (array keys, % operator, int parameters).

Seen on: PHP

Meaning

Using floats as array keys or with modulo truncates them. PHP 8.1 makes the precision loss visible.

Common causes

  • Float used as an array key
  • Modulo with float operands
  • Float passed to an int parameter

⚡ Quick fix

  1. Round explicitly: (int) round($x) or intdiv()
  2. Use fmod() for float modulo

Detailed fix by platform

PHP

  1. $page = (int) floor($offset / $perPage);

How to diagnose

  1. Expression — Which conversion?
  2. Intent — Truncate, round or keep decimals?

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