开发者

null with PHP < and > operators

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜