1.2.465. Float Conversion As Index¶
Only integers and strings are possible types when used for array index. Until PHP 8.1, floats were converted to integer by truncation. Since PHP 8.1, a deprecated message is emitted.
The implicit conversion of float to int which leads to a loss in precision is now deprecated. This affects array keys, int type declarations in coercive mode, and operators working on integers.
<?php
$a = [];
$a[15.5]; // deprecated, as key value loses the 0.5 component
$a[15.0]; // ok, as 15.0 == 15
?>
See also Implicit incompatible float to int conversions.
1.2.465.1. Specs¶
Short name |
Arrays/FloatConversionAsIndex |
Rulesets |
All, Analyze, Changed Behavior, CompatibilityPHP81, CompatibilityPHP82 |
Exakat since |
2.3.1 |
PHP Version |
With PHP 8.1 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Features |
array |
Available in |