Error Identifier: catch.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 NewException instead */
class OldException extends \Exception
{
}
try {
// ...
} catch (OldException $e) {
// ...
}
Why is it reported? #
The catch clause references a class that has been marked with a @deprecated PHPDoc tag. The class is scheduled for removal or replacement, and any usage of it – including catching it as an exception – should be migrated to the recommended alternative.
This rule is provided by the phpstan-deprecation-rules package.
How to fix it #
Replace the deprecated class with its recommended replacement as indicated in the deprecation message:
<?php declare(strict_types = 1);
try {
// ...
-} catch (OldException $e) {
+} catch (NewException $e) {
// ...
}
How to ignore this error #
You can use the identifier catch.deprecatedClass to ignore this error using a comment:
// @phpstan-ignore catch.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: catch.deprecatedClass
Rules that report this error #
- PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules