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;
function foo(?string $s = null) {}
?>
See also Much ado about null, Null Hell and How to Get Out of It, Avoiding Unnecessary Null Checks
Related : Nullable, Null Pattern