0
0
PHPprogramming~10 mins

Isset, empty, and is_null behavior in PHP - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Isset, empty, and is_null behavior
Start
Check isset(var)
Yesisset = true
Check empty(var)
Yesempty = true
Check is_null(var)
Yesis_null = true
is_null = false
End
The flow checks if a variable is set, then if it is empty, and finally if it is null, showing how each function behaves step-by-step.
Execution Sample
PHP
<?php
$a = null;
$b = 0;
$c = '';
$d = 'hello';

var_dump(isset($a));
var_dump(empty($a));
var_dump(is_null($a));
?>
This code tests isset, empty, and is_null on a variable set to null.
Execution Table
StepVariableisset()empty()is_null()Explanation
1$a = nullfalsetruetrue$a is null, so isset is false, empty is true, is_null is true
2$b = 0truetruefalse$b is zero, isset true, empty true (0 is empty), is_null false
3$c = ''truetruefalse$c is empty string, isset true, empty true, is_null false
4$d = 'hello'truefalsefalse$d is non-empty string, isset true, empty false, is_null false
5$e not setfalsetruefalse$e is not set, isset false, empty true, is_null false
💡 All variables checked; isset false if variable not set or null; empty true for null, 0, '', false; is_null true only if variable is null.
Variable Tracker
VariableInitialAfter Step 1After Step 2After Step 3After Step 4After Step 5
$aundefinednullnullnullnullnull
$bundefinedundefined0000
$cundefinedundefinedundefined''''''
$dundefinedundefinedundefinedundefined'hello''hello'
$eundefinedundefinedundefinedundefinedundefinedundefined
Key Moments - 3 Insights
Why does isset($a) return false when $a is null?
Because isset returns false if the variable is null or not set, as shown in execution_table row 1.
Why is empty($b) true when $b is 0?
Because empty considers 0 as empty (falsey), so empty returns true, as shown in execution_table row 2.
Why does is_null($e) return false even though $e is not set?
Because is_null returns false if the variable is not set, as shown in execution_table row 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of isset($c) at step 3?
Atrue
Bfalse
Cnull
Derror
💡 Hint
Check the 'isset()' column for $c at step 3 in the execution_table.
At which step does empty() return false?
AStep 1
BStep 2
CStep 4
DStep 5
💡 Hint
Look at the 'empty()' column in the execution_table and find where it is false.
If $a was set to false instead of null, what would isset($a) return?
Afalse
Btrue
Cnull
Derror
💡 Hint
Recall that isset returns true for variables set to false, only false for null or unset variables.
Concept Snapshot
isset(var): true if var exists and is not null
empty(var): true if var is falsey (null, 0, '', false, etc.)
is_null(var): true if var is null
isset false if var is null or unset
empty true for many falsey values
is_null true only for null
Full Transcript
This visual execution shows how PHP functions isset, empty, and is_null behave with different variable values. isset returns false if the variable is null or not set, true otherwise. empty returns true for variables that are falsey like 0, empty string, null, or false. is_null returns true only if the variable is null. The execution table traces these functions step-by-step on variables with values null, 0, empty string, a non-empty string, and an unset variable. The variable tracker shows how variables change or remain undefined. Key moments clarify common confusions like why isset returns false for null and why empty returns true for 0. The quiz tests understanding by asking about specific steps and hypothetical changes. This helps beginners see exactly how these PHP functions behave in practice.