Error Identifier: traitUse.deprecatedClass
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 NewFeature instead */
class OldFeature
{
}
class Foo
{
use OldFeature;
}
Why is it reported? #
This error is reported by the phpstan-deprecation-rules extension.
A use statement in a class body references a deprecated class. The class has been marked with @deprecated and is scheduled for removal or replacement. Any usage of it should be migrated to the recommended alternative.
How to fix it #
Replace the deprecated class with the recommended replacement:
class Foo
{
- use OldFeature;
+ use NewFeature;
}
If the calling code is itself deprecated, the error will not be reported. Mark the class as deprecated if it is part of a deprecation migration:
+/** @deprecated */
class Foo
{
use OldFeature;
}
How to ignore this error #
You can use the identifier traitUse.deprecatedClass to ignore this error using a comment:
// @phpstan-ignore traitUse.deprecatedClass
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: traitUse.deprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules