웹&컴퓨팅

[PHP] isset, is_null, ===null, ==null, empty

x2chi 2015. 6. 9. 13:39
반응형

As you can see in the following table empty($foo) is equivalent to $foo==null and is_null($foo) has the same function of $foo===null. The table also show some tricky values regarding null comparison.

Personally, I never use empty() and is_null() functions.

        isset  is_null ===null  ==null  empty
 null |   F   |   T   |   T   |   T   |   T   |
unset |   F   |   T   |   T   |   T   |   T   |
  ""  |   T   |   F   |   F   |   T   |   T   |
  []  |   T   |   F   |   F   |   T   |   T   |
    0 |   T   |   F   |   F   |   T   |   T   |
false |   T   |   F   |   F   |   T   |   T   |
 true |   T   |   F   |   F   |   F   |   F   |
    1 |   T   |   F   |   F   |   F   |   F   |
   \0 |   T   |   F   |   F   |   F   |   F   |

 

 

 

 

 

http://stackoverflow.com/a/15607549

반응형