Menu
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 NewHelper instead */
trait OldHelper
{
public const VERSION = '1.0';
}
echo OldHelper::VERSION;
Why is it reported? #
This error is reported by the phpstan-deprecation-rules extension.
A class constant is accessed directly on a trait that has been marked as @deprecated. Deprecated traits are planned for removal in a future version, and code should not rely on their constants.
How to fix it #
Access the constant from a non-deprecated source instead:
-echo OldHelper::VERSION;
+echo NewHelper::VERSION;
How to ignore this error #
You can use the identifier classConstant.deprecatedTrait to ignore this error using a comment:
// @phpstan-ignore classConstant.deprecatedTrait
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: classConstant.deprecatedTrait