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

No Hidden Nullable

<?php

function foo(string $a = null) {}


const A  = null;
function bar(string $a = A) {}

foo();  // Deprecated 
bar();  // Fatal error

?>

A hidden nullable is a, now deprecated, PHP features where typed parameters with a default value of null are automatically nullable.

Well, that is true only if PHP can spot the null at compilation time: when the null is hidden (sic) in a constant, then it is not recognized, and it leads to a Fatal Error.

This is due to PHP postponing the evaluation of the constant to execution phase.

See Also

PHP Features

Last updated: 22 October 2026