Implicitly marking parameter $%s as nullable is deprecated, the explicit nullable type must be used instead¶
Description¶
Until PHP 8.4, it is possible to use a default value of null, on a parameter that is not nullable. This special situation makes the parameter nullable: it may be omitted, or explicitely passed as null. This is a hidden type, as the null type is not explicit, yet it is fully usable.
In PHP 8.4, this is not possible anymore. For consistency reasons, the type must be explicitly displayed. Until then, it was silent.
Example¶
<?php
function foo(string $s = null) {}
class X {
function foo(string $s = null) {}
}
?>
Literal Examples¶
foo(): Implicitly marking parameter $s as nullable is deprecated, the explicit nullable type must be used instead
X::bar(): Implicitly marking parameter $s as nullable is deprecated, the explicit nullable type must be used instead
Solutions¶
Add
?
to the type.Add
null|
to the type.Use a default value in the range of the specified type.
Changed Behavior¶
This error may appear in different PHP versions implicitNullable.