Possible Duplicate:
What's the difference between is_null($var) and ($var === null)?
PHP has two (that I know of, and three if you count isset()
) methods to determine if a value is null: is_null()
and === null
. I have heard, but not confirmed, that === null
is faster, but in a code review someone strongly suggested that I use is_null()
instead as it is specifically designed for the null-evaluation purpose. He also started talking about math or something.
Anyway, the fact that is_null()
is apparently slower also leads me to believe that it's doing more than === null
does and is probably preferred. Is there any reason to use one or the other? Is one always preferred? What about isset()
?
As an addendum to possibly not get this question closed, what about isset()
vs. is_null()
? It seems that all isset()
will do is suppress the notice, so unless you actually want a notice for an undefined variable, any reason to use is_null()
instead? How about if you know the variable is initialized at the time?
Finally, is there any mathematical reason to prefer is_null()
over === null
? Something about null not being comparable?
===
is no longer faster thanis_null
.