Skip to content

implicit-nullable-parameter

PHPsuspiciousno fixdefault: offphp/phpstan

Reports a parameter with a type that does not allow null and a null default (int $a = null).

The parameter is nullable only through the default, which is deprecated since PHP 8.4 and a notice to code that runs there. The type says one thing and the default another.

To fix, write the nullable type: ?int $a = null.

Reported
<?php
function a(int $a = null, ?int $b = null, int|null $c = null, $d = null, mixed $e = null) {}
class P { function __construct(public $x = null, public string $y = null) {} }
php:
lint:
rules:
implicit-nullable-parameter: warn # off (default), warn, error

Enabled by the presets: php/phpstan.

Suppress one line with sudsy-disable-next-line implicit-nullable-parameter in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
phpstan parameter.implicitlyNullable partial A typed parameter with a null default and no ? or null in its type.