Error Identifier: classConstant.deprecatedTrait
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 DeprecatedHelper
{
public const VERSION = '1.0';
}
class MyClass
{
use DeprecatedHelper;
}
function doFoo(): void
{
echo MyClass::VERSION;
}
Why is it reported? #
The class constant being accessed belongs to a trait that is marked as @deprecated. Accessing constants from deprecated traits indicates reliance on code that is scheduled for removal. This rule is part of the phpstan-deprecation-rules package and helps identify usages that should be migrated.
How to fix it #
Replace the deprecated constant access with the recommended alternative:
<?php declare(strict_types = 1);
function doFoo(): void
{
- echo MyClass::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