Error Identifier: staticProperty.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 OldHelper
{
public static string $version = '1.0';
}
class MyClass
{
use OldHelper;
}
echo OldHelper::$version;
Why is it reported? #
This error is reported by the phpstan-deprecation-rules extension.
A static property is accessed on a trait that is marked as @deprecated. Deprecated traits are scheduled for removal or replacement. Accessing static properties on them ties the code to an API that will eventually be removed.
How to fix it #
Use the recommended replacement trait or class instead:
-echo OldHelper::$version;
+echo NewHelper::$version;
If the calling code is itself deprecated, the error will not be reported. Mark the function or class as deprecated if it is part of a deprecation migration:
+/** @deprecated */
function doFoo(): void
{
echo OldHelper::$version;
}
How to ignore this error #
You can use the identifier staticProperty.deprecatedTrait to ignore this error using a comment:
// @phpstan-ignore staticProperty.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: staticProperty.deprecatedTrait