isset() vs empty() vs is_null() in PHP
isset() checks a variable exists and isn't null; empty() also treats '', 0, and false as empty; is_null() strictly checks for null. Learn the differences.
Published September 18, 2026
isset($var) returns true if a variable is set and its value is not null. empty($var) returns true if the variable is unset, null, false, 0, '0', an empty string, or an empty array. is_null($var) returns true only if the variable exists and its value is exactly null.
Common causes
- PHP treats several distinct values (0, '', false, null, unset) as loosely equivalent in boolean contexts, so these functions exist to let you pick exactly which cases you care about
How to fix it
- Use isset() when checking whether an array key or variable exists before using it, to avoid 'Undefined variable/index' warnings
- Use empty() when you want to treat 0, '', and false the same as 'not set' — common for form input validation
- Use is_null() (or === null) when you specifically need to distinguish null from other falsy values like 0 or an empty string
Example
$a = 0;
isset($a); // true — it exists
empty($a); // true — 0 counts as empty
is_null($a); // false — it's 0, not nullFAQ
Does isset() throw a warning on an undefined array key?
No — isset() is specifically designed to safely check for existence without triggering a warning, unlike directly accessing the key.