syedrakib syedrakib - 1 year ago 58
PHP Question

difference between is_null "== NULL" and "=== NULL" in PHP

Possible Duplicate:

php == vs === operator

i have the following code fragment and it doesn't make sense to me why would NULL be evaluated in 3 different ways. Consider the variable
as UNKNOWN - we don't know whether it's still an array or a NULL. That's what we are trying to check.

if (is_null($uploaded_filenames_array)){
echo "is_null";
echo "is_NOT_null";
if ($uploaded_filenames_array == NULL){
echo "NULL stuff";
echo "not NULL stuff";
if ($uploaded_filenames_array === NULL){
echo "NULL identity";
echo "not NULL identity";

i am getting the following response:

NULL stuff
not NULL identity

can somebody help to understand what is the programmatic difference between these 3 ways of checking NULL?

Answer Source

is_null($a) is same as $a === null.

($a === null is bit faster than is_null($a) for saving one function call, but it doesn't matter, just choose the style you like.)

For the difference of === and ==, read PHP type comparison tables

$a === null be true only if $a is null.

But for ==, the below also returns true.

null == false
null == 0
null == array()
null == ""
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download