Null means "nothing". The var has not been initialized.
Null 意思是nothing。這個變數還沒被初始化。
False means "not true in a boolean context". Used to explicitly show you are dealing with logical issues.
False意思是"在boolean中不是true"。用於明確表明你正在處理的邏輯問題。
0 is an int. Nothing to do with the rest above, used for mathematics.
0是數字。與上面無關,用於數學。
gcb:
you pretty much have to always test for ===null or ===false, depending on the function. or for both, in cases such as filter_input()/filter_var()
你最好使用 === null 或 === false 去測試他。
一些測試:
var_dump( null < -1 ); #bool(true)
var_dump( null < 0 ); #bool(false)
var_dump( null < 1 ); #bool(true)
Comparisons of $x with PHP functions
Loose comparisons with ==
Strict comparisons with ===
圈紅處在 loose comparisions == 中為true |
參考資料:
http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php Null vs. False vs. 0 in PHP
http://www.seayee.net/article/info_115.html 讓 空字符串、0、null和 strval()、intval()、empty()、is_numeric()、is_string() 之間的關係
http://php.net/manual/en/types.comparisons.php PHP type comparison tables
沒有留言:
張貼留言