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() checks that a variable exists and is not null, empty() checks that it is missing or falsy, and is_null() checks that it is exactly null. They answer three different questions.
The concept
isset($x) is true when $x is defined and not null, even if it is 0, '' or false. empty($x) is true for anything falsy: 0, '0', '', false, null, [] and undefined variables.
is_null($x) is true only for null, but it raises a warning on an undefined variable, whereas isset and empty never do.
Result table
Practical examples
Safe array access
if (isset($_GET['page'])) { $page = (int)$_GET['page']; }Null coalescing is shorter
$page = $_GET['page'] ?? 1;The '0' trap
$qty = '0';
if (empty($qty)) { echo 'empty!'; } // runs, though '0' was submittedDistinguish null from false
$v = false;
var_dump(is_null($v)); // false
var_dump(isset($v)); // trueCommon mistakes
- Using empty() on form values where 0 or '0' is valid.
- Using is_null() on a possibly undefined variable.
- Writing isset($a) && $a !== '' when ?? would do.
Key takeaways
- isset: exists and not null.
- empty: missing or falsy.
- is_null: exactly null.
FAQ
Which should I use for form input?
isset or ?? for presence, then validate explicitly; avoid empty() when 0 is allowed.
Does isset work on array keys?
Yes, isset($arr['k']) is false if the key is missing or its value is null.