Can somebody explain how null is mapped in these statements?

null>0; //=> bool(false)
null<0; //=> bool(false)
null==0; //=> bool(true)

but

null<-1; // => bool(true)

I assume it's some mapping problem, but can't crack it.

Tried with PHP 5.3.5-1 with Suhosin-Patch.

Comments

Erm, what is it you are trying to do? All those statements are valid.

Written by Khez

Use === type checked equality if you want accuracy

Written by JohnP

If only PHP's null was like an SQL null...

Written by Marc B

don`t try to find the logic, it was more like mindfuck question, which I encountered during codding

Accepted Answer

I would point you to a few pages: http://php.net/manual/en/types.comparisons.php http://php.net/manual/en/language.operators.comparison.php http://php.net/manual/en/language.types.boolean.php

So in your final example:

null<-1 => bool(true)

The null is cast to false and the -1 is cast to true, false is less than true

In your first two examples null is cast to false and 0 is cast to false, false is not less than or greater than false but is equal to it.

Ohh the fun of null ! :D

Written by Tnem
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki