Monday, April 18, 2011

The difference between the "isset", "empty" and "is_null"

Most the times I have noticed the beginners are confused in testing the variable, whether it contains some data or not. Most of the time these checks fail as the wrong function is being used to assert the correct value. While it is important to be checking values, it is equally important to understand the difference between the different methods of checking and testing values for empty, null, or if they are set.

The following difference chart between "isset", "empty" and "is_null" will be quite helpful for everyone.


TESTNot SetNULLZeroFALSENumeric ValueEmpty String
Comparison Table
isset()bool(false)

bool(false)bool(true)bool(true)bool(true)bool(true)
empty()bool(true)bool(true)bool(true)bool(true)bool(false)bool(true)
is_null()bool(true)bool(true)

bool(false)bool(false)

bool(false)bool(false)

5 comments: