Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Null

null is a special data type that represents a variable with no value or an undefined value. It is used to indicate the absence of a value. In other words, when a variable is assigned the value null, it means that the variable exists but has no valid data.

null may be used as a default value for variables, parameter or properties that are expected to hold some value later but don’t have a value assigned initially. It was also be used to unset a variable and free up memory, when using the operator (unset).

There is also a design pattern called Null Pattern, although its main goal is to remove usage of null and replace it with an actual object.

<?php

    $a = null;
    $B = NULL;
    $c = \null;

    // same as  null|string $s 
    function trumpet(?string $s = null) {}

?>

Documentation

See Also