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 Foo
{
private function doFoo(int $value, string $unused): void
{
echo $value;
}
}
Why is it reported? #
The private method declares the parameter $unused but never reads it in its body. A parameter that no code path uses is dead — it either signals a leftover from refactoring or a mistake where the parameter was meant to be used.
Only private methods are reported. A public or protected method’s signature may be dictated by an interface, a parent class, or an override, so its parameters cannot always be removed. A private method has no callers outside the class, so its signature is not a contract. Magic methods (whose names start with __) are excluded because the engine dictates their signature, and the constructor has its own constructor.unusedParameter rule. Parameters referenced by a @phpstan-assert tag or a conditional return type are also not reported.
This rule is part of PHPStan’s dead code analysis. It is reported at rule level 4 and above, and is currently part of Bleeding Edge.
How to fix it #
Remove the unused parameter:
- private function doFoo(int $value, string $unused): void
+ private function doFoo(int $value): void
{
echo $value;
}
Or use the parameter in the method body if it was intended to be read:
private function doFoo(int $value, string $unused): void
{
echo $value;
+ echo $unused;
}
How to ignore this error #
You can use the identifier method.unusedParameter to ignore this error using a comment:
// @phpstan-ignore method.unusedParameter
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: method.unusedParameter