PHP 8.1 – New Warning being throw when converting float to int

PHP 8.1 – New Warning being throw when converting float to int

numbers going down, dark theme

For plain float type of variables or float being marked as string, there will be thrown a PHP Deprecation about potential data loss.

Emit an E_DEPRECATED deprecation diagnostic for implicit conversion from float and float strings to int if the floating point number is not integer-compatible.

If the conversion happens from a float the diagnostic message is:

Implicit conversion to int from non-compatible float %f

If the conversion happens from a float-string the diagnostic message is:

Implicit conversion to int from non-compatible float-string %s

Where %f and %s correspond to the value of the float/float-string value which is not integer-compatible.

Raise these deprecation diagnostics to TypeError in the next major version (PHP 9.0).

More about PHP 8.1

Read about all PHP 8.1 features and changes in here.