Puddinq.com sharing knowledge

Using isset() empty() and is_null()

Using isset() empty() and is_null()

Validating the input is very important, but you want te write lean code. So if you are in doubt
about using !empty only, or !empty && isset here’s the difference:

Value of variable ($var) isset($var) empty($var) is_null($var)
“” (an empty string) bool(true) bool(true) bool(false)
” ” (space) bool(true) bool(false) bool(false)
FALSE bool(true) bool(true) bool(false)
TRUE bool(true) bool(false) bool(false)
array() (an empty array) bool(true) bool(true) bool(false)
NULL bool(false) bool(true) bool(true)
“0” (0 as a string) bool(true) bool(true) bool(false)
0 (0 as an integer) bool(true) bool(true) bool(false)
0.0 (0 as a float) bool(true) bool(true) bool(false)
var $var; (a variable declared, but without a value) bool(false) bool(true) bool(true)
NULL byte (“\ 0”) bool(true) bool(false) bool(false)