Menu

← Back to traitUse.*

Error Identifier: traitUse.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);

namespace App;

/** @deprecated Use NewTrait instead */
trait OldTrait
{
    public function doSomething(): void
    {
    }
}

class Foo
{
    use OldTrait;
}

Why is it reported? #

This error is reported by the phpstan/phpstan-deprecation-rules package.

The class uses a trait that is marked as @deprecated via the use statement in the class body. Deprecated traits are scheduled for removal or replacement and should no longer be used in new code.

How to fix it #

Replace the deprecated trait with its recommended replacement:

 <?php declare(strict_types = 1);
 
 namespace App;

 class Foo
 {
-    use OldTrait;
+    use NewTrait;
 }

If the class is itself deprecated, the error will not be reported:

 <?php declare(strict_types = 1);
 
 namespace App;

+/** @deprecated */
 class Foo
 {
     use OldTrait;
 }

How to ignore this error #

You can use the identifier traitUse.deprecatedTrait to ignore this error using a comment:

// @phpstan-ignore traitUse.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: traitUse.deprecatedTrait

Rules that report this error #

  • PHPStan\Rules\Deprecations\RestrictedDeprecatedClassNameUsageExtension [1] phpstan/phpstan-deprecation-rules

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.