Menu

← Back to method.*

Error Identifier: method.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 function help(): void
	{
	}
}

class Foo
{
	use OldHelper;
}

function doFoo(Foo $foo): void
{
	$foo->help(); // ERROR: Call to method help() of deprecated trait OldHelper.
}

Why is it reported? #

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

The method being called is declared in a trait that has been marked as deprecated with the @deprecated PHPDoc tag. Even though the method itself may not be deprecated, calling it through a class that uses a deprecated trait signals usage of deprecated functionality. The deprecation notice typically suggests a replacement to use instead.

How to fix it #

Replace the usage of the deprecated trait with the suggested replacement:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	use OldHelper;
+	use NewHelper;
 }

Or call a method from a non-deprecated source if one is available.

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.