Implicit Nullable

A typed argument with a default value of null was also implicitly nullable: it would accept null as a value. This is deprecated in PHP 8.4, and will be removed in PHP 9.0. It is recommended to make the nullable type explicit in the code.

That issue applies to arguments in methods and functions, but not on properties or returned values.

PHP code

<?php

function foo(int $a = null) {
     var_dump($a);
}

foo(1);
foo(null);

?>

Before

int(1)
NULL

After

PHP Deprecated:  foo(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in /codes/implicitNullable.php on line 3

Deprecated: foo(): Implicitly marking parameter $a as nullable is deprecated, the explicit nullable type must be used instead in /codes/implicitNullable.php on line 3
int(1)
NULL

PHP version change

This behavior was deprecated in 8.4

This behavior changed in 9.0

Error Messages