Implicitly Nullable Parameter Types are Deprecated in PHP 8.4

Implicitly Nullable Parameter Types are Deprecated in PHP 8.4

PHP allows defining parameter types in function and method signatures. PHP supports nullable type declarations with the ?T syntax, and with the T|null syntax.

Since PHP 8.4, implicitly nullable parameter types are deprecated. This means that the following function signatures are deprecated, and PHP will issue a deprecation warning:

<?php

function run(string $name = null): void {}

function test(int|float $num = null): void {}

Example will output:

Deprecated: run(): Implicitly marking parameter $name as nullable is deprecated ...
Deprecated: test(): Implicitly marking parameter $num as nullable is deprecated ...

In the previous example, a deprecation warning can be resolved by making parameters explicitly nullable:

<?php

function run(?string $name = null): void {}

function test(int|float|null $num = null): void {}

Leave a Comment

Cancel reply

Your email address will not be published.