I have recently stumbled upon a situation that seems to be a bug at best. Both null
and false
appear to be evaluated to lower but not equal to negative infinity when used in comparisons.
My current test case:
var_dump(
PHP_OS,
PHP_VERSION,
null == 0, # true
false == 0, # true
INF==INF, # true
(-1*INF) == (-1*INF), # true
(-1*INF) < (-1*INF), # false!
(-1*INF) > (-1*INF), # false!
'Insane In The Membrane',
null == (-1*INF), # false!?
false == (-1*INF), # false!?
null < (-1*INF), # true!
false < (-1*INF) # true!
);
This was run on various PHP Versions and on some windows machines that I had access to. All had the surprising same result.
Ignoring the first two debug dumps, The next 6 results are what you'd expect if you're a seasoned PHP developer. The first two are due to type juggling and the last 4, are due to PHP and math.
Now the last four are what's bugging me.
I'm uncertain if it is even valid in math to have something lower than negative infinity.
What's stranger still is the combination of the first two and the last two comparisons. Somehow the same type juggling algorithm makes this valid:
var_dump(
'Insane In The Membrane (Redux)',
(null == 0) && (null < (-1*INF)), # true
(false == 0) && (false < (-1*INF)) # true
);
If anyone can give any insight as to how these type casts are being evaluated so differently and why that would be greatly appreciated.
P.S. I have tried searching SO again and again and again, the PHP Manual and even the PHP bug tracker, all to no avail. I tried looking through the C source code to determine the bits and pieces that make this code work the way it does. Still no dice.
null
certainly isn't greater than -inf, and it isn't equal to -inf. So by elimination...-inf
. I'm puzzled by what exactly is passed to thecmp
assembly instruction. I don't know how infinity is handled and right now I have no idea hownull
andfalse
are handler either.