Skip to content
Justice Tech School

null, isset and empty

null means no value. isset checks that a variable exists and is not null, empty checks for falsy values and is_null tests null. The null coalescing operator ?? shortens many checks.

Example
$a = null; $b = 0; $c = "";
var_dump(isset($a), isset($b), empty($b), empty($c), is_null($a));
$user = ["name" => "Ada"];
echo $user["age"] ?? "unknown", "\n";
$x ??= 5;
echo $x, "\n";

Result

bool(false)
bool(true)
bool(true)
bool(true)
bool(true)
unknown
5

Exercise

Is the variable set?

($x)

Quiz Test

What does isset return for null?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.