Error Identifier: parameter.missing
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
class Base
{
public function doFoo(string $name, int $age): void
{
}
}
class Child extends Base
{
public function doFoo(string $name): void
{
}
}
Why is it reported? #
An overriding method is missing a parameter that exists in the parent method. When a child class overrides a method, it must accept at least the same parameters as the parent method. Removing a parameter from an overriding method violates the Liskov Substitution Principle – code that calls the parent method with all its parameters would break when given an instance of the child class.
How to fix it #
Add the missing parameter to the overriding method:
class Child extends Base
{
- public function doFoo(string $name): void
+ public function doFoo(string $name, int $age): void
{
}
}
How to ignore this error #
You can use the identifier parameter.missing to ignore this error using a comment:
// @phpstan-ignore parameter.missing
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: parameter.missing