null with PHP < and > operators-ThrowExceptions

Exception or error:

Can somebody explain how null is mapped in these statements?

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


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.

How to solve:

I would point you to a few pages:

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 ! 😀

Leave a Reply

Your email address will not be published. Required fields are marked *