Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

PHP type null

The null type has exactly one value, null.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

function clear(): null

The null type has exactly one value, null. Since PHP 8.2 it can be declared on its own. A nullable result can represent absence, but an array key storing null still exists. A presence check and a non-null check answer different questions, which matters for optional configuration fields.

function clear(): null { return null; }
$settings = ['quota'=>clear()];
echo json_encode([$settings['quota'], array_key_exists('quota',$settings), isset($settings['quota'])]);
[null,true,false]

Examples

<?php
function clear(): null { return null; }
$settings = ['quota'=>clear()];
echo json_encode([$settings['quota'], array_key_exists('quota',$settings), isset($settings['quota'])]);

Result

[null,true,false]

Sources