website/errors/parameter.deprecatedInterface.md
<?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.
{
}
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.
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
{
}