2012-04-29 40 views
-4

可能重复:
What's the difference between is_null($var) and ($var === null)?is_null VS ===空

是否有下面的代码之间的任何差别:

if(is_null($x)) { ... 

if($x===null) { ... 
+2

文档不够吗? [阅读评论](http://php.net/manual/en/function.is-null.php)和[谷歌似乎有很多关于这方面的结果 - 你可能也想考虑'===' !](http://hakre.wordpress.com/2011/03/29/php-is_null-vs-null/) – 2012-04-29 06:18:06

+0

http://stackoverflow.com/questions/4662588/whats-the-difference-between-is -nullvar-and-var-null – 2012-04-29 06:21:11

+2

这个问题不应该upvoted无用。许多确切的重复项已经存在 – 2012-04-29 06:21:45

回答

2

是的。 ==是一个宽松的比较,这意味着不仅仅是NULL将在第二个版本中产生true。请参阅type comparison tables

+0

NULL并不意味着真/假,它意味着未知的值,所以在使用它时要小心! – Philip 2012-04-29 06:23:40