2012-04-29 20 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