null cannot be marked as nullable¶
Description¶
Since PHP 8.2, null (like false and true) can be used directly as a standalone type. But null already means exactly one thing: the value null. Marking it nullable with a leading ?, as in ?null, would only mean null or null, which is entirely redundant, so PHP rejects it.
Example¶
<?php
function test(): ?null
{
}
?>
Literal Examples¶
null cannot be marked as nullable
Solutions¶
Remove the
?and usenullon its own.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.