Caution when using variables with the value NAN (or directly NAN, which would not be logical) if the value is converted in any form (integer, string or other non-float format)!
In that case, NAN is converted to 0. (e.g. as an index in an array, argument of a method that takes it as a non-float parameter, etc.). This bug has been reported several times, but is still present in the current version PHP 7.3.15.
Example 1:
$array = [0 => 'zero', 1 => 'one', 2 => 'two'];
$index = NAN;
echo $array[$index]; // echo 'zero' and not as axcepted throws an exception or at least a warning 'undefined offset NAN ...'
Example 2:
function f((int) $p) { return $p; }
echo f(NAN); // echo 0 because the argument (NAN) has been converted to integer (0)
It would have to be checked in both cases explicitly for is_nan():
1: if(is_nan($index)){
}else{
echo $array[$index];
};
2: function f($p){ // without converting!!!
if(is_nan($p)){
}else{
return (int)$p; // actually a correct conversion to Integer would have to be checked because the parser does not check this here.
};
}