Skip to content

PHP Tutorial Data Types

NULL

Lesson 41 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

null means no value. It is the only value of the null type, and it is written null (case does not matter, but lowercase is the standard).

index.php
PHP
<?php
$middleName = null;

var_dump($middleName);
Output
OUTPUT
NULL

When a variable is null

A variable is null when:

  1. You assign null to it.
  2. You never gave it a value (PHP also gives a warning when you read it).
  3. You called unset() on it.

A function that has nothing to return also gives null.

index.php
PHP
<?php
function sayHi(): void
{
    echo "Hi\n";
}

$result = sayHi();
var_dump($result);
Output
OUTPUT
Hi
NULL

Checking for null

index.php
PHP
<?php
$value = null;

var_dump($value === null);
var_dump(is_null($value));
var_dump(isset($value));
Output
OUTPUT
bool(true)
bool(true)
bool(false)

null is not 0 and not “”

These three look similar but mean different things.

ValueMeaning
nullNo value at all
0The number zero
""A string with no characters
index.php
PHP
<?php
var_dump(null === 0);
var_dump(null === "");
var_dump(null == false);
Output
OUTPUT
bool(false)
bool(false)
bool(true)

Loose comparison (==) treats null as equal to false, 0 and "". Strict comparison (===) does not. That is why professional PHP uses ===.

A default for null

The null coalescing operator ?? gives a fallback when a value is null or missing.

index.php
PHP
<?php
$nickname = null;
echo $nickname ?? "No nickname";
Output
OUTPUT
No nickname

More on that in Null Coalescing Operator.

lightbulb
null is how you say "optional"
A function parameter that may be missing, a database column that may be empty and a user without a profile photo are all naturally null.