Error Identifier: classConstant.deprecated
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);
class Foo
{
/** @deprecated Use NEW_VALUE instead */
public const OLD_VALUE = 'old';
public const NEW_VALUE = 'new';
}
echo Foo::OLD_VALUE;
Why is it reported? #
This error is reported by the phpstan-deprecation-rules extension.
The code accesses a class constant that has been marked with a @deprecated PHPDoc tag. Deprecated constants are scheduled for removal in a future version, and new code should not rely on them.
In the example above, the constant OLD_VALUE on class Foo is deprecated.
How to fix it #
Replace the usage with the recommended replacement constant:
<?php declare(strict_types = 1);
-echo Foo::OLD_VALUE;
+echo Foo::NEW_VALUE;
How to ignore this error #
You can use the identifier classConstant.deprecated to ignore this error using a comment:
// @phpstan-ignore classConstant.deprecated
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.deprecated