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
Alternatives
- Remove the
?and usenullon its own.
Related error messages
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See