Error Identifier: parameter.deprecatedInterface
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);
/** @deprecated Use NewInterface instead */
interface OldInterface
{
}
function doFoo(OldInterface $param): void // ERROR: Parameter $param of function doFoo() has typehint with deprecated interface OldInterface.
{
}
Why is it reported? #
This error is reported by phpstan-deprecation-rules.
A function or method parameter uses a deprecated interface as its type declaration. Using deprecated interfaces in parameter types ties your code to interfaces that are planned for removal, making future migration harder.
The error applies to native type declarations on function and method parameters. It is not reported when the function or method itself is already marked as @deprecated.
How to fix it #
Replace the deprecated interface with its recommended replacement:
<?php declare(strict_types = 1);
-function doFoo(OldInterface $param): void
+function doFoo(NewInterface $param): void
{
}
If you need to support both the old and new interface during a transition period, use a union type:
<?php declare(strict_types = 1);
-function doFoo(OldInterface $param): void
+function doFoo(OldInterface|NewInterface $param): void
{
}
How to ignore this error #
You can use the identifier parameter.deprecatedInterface to ignore this error using a comment:
// @phpstan-ignore parameter.deprecatedInterface
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.deprecatedInterface
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules