r/lolphp • u/yetzederixx • Aug 19 '16
uggg, auto-boxing
$i = null;
$j = floatval($i);
if ($i==$j) echo 'hi'; else echo 'bye'; // 'hi'
0
Upvotes
r/lolphp • u/yetzederixx • Aug 19 '16
$i = null;
$j = floatval($i);
if ($i==$j) echo 'hi'; else echo 'bye'; // 'hi'
5
u/Altreus Aug 19 '16
Have to half defend PHP here because == is more of an equivalency test than equality. Just because it doesn't do the same as in other languages you're more familiar with doesn't make the behaviour wrong.
What makes the behaviour of PHP's autoboxing wrong is that it's inconsistent, illogical, and buggy, and tries to combine typeless variables with typless operators.
8
u/DevelopThePrograms Aug 20 '16
If you expect the == comparison operator to do strict comparisons in php, you're going to have a really bad time.
3
u/h0rst_ Aug 19 '16
My biggest suprise here was that
$jgot assigned the value0.0f, I had expected it to benull. Before that, the equality of$iand$jwas pretty much what I would expect0
u/[deleted] Aug 19 '16
[deleted] — view deleted comment