Float Used As Array¶
A float is not an array, but it is possible to use the array syntax with it. The values are then always null, and since PHP 7.4, a warning is emitted.
PHP code¶
<?php
$a = 45.6;
var_dump($a['dsds']); // null
var_dump($a[1]); // null
var_dump(((string) $a)[1]); // 5
?>
Before¶
NULL
After¶
PHP Warning: Trying to access array offset on float
Warning: Trying to access array offset on float
NULL
PHP version change¶
This behavior changed in 7.4