开发者

php using variable type checking functions to check if null

开发者 https://www.devze.com 2023-03-01 08:32 出处:网络
Can I use functions like is_integer(), is_string(), and other like them as a reliable check to see if the variable is null? I guess what I am asking is if th开发者_开发技巧e variable is null with they

Can I use functions like is_integer(), is_string(), and other like them as a reliable check to see if the variable is null? I guess what I am asking is if th开发者_开发技巧e variable is null with they all return false?


Use type comparison.

$somevar === null


You can use either is_null() or use type comparison (===). They're virtually the same, except that type comparison will be slightly faster (by slightly I mean so abysmal that it almost doesn't matter).


All of the is_*() functions tests the type of a value, thats theire main purpose. To test, if a variable is null, just test it ;)

is_null($var)
0

精彩评论

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