Menu

← Back to method.*

Error Identifier: method.deprecatedClass

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.

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

Code example #

<?php declare(strict_types = 1);

/** @deprecated Use NewLogger instead */
class OldLogger
{
	public function log(string $message): void
	{
	}
}

$logger = new OldLogger();
$logger->log('hello');

Why is it reported? #

A method is being called on an instance of a class that has been marked as @deprecated. Even though the method itself is not deprecated, the entire class is deprecated, which means all usage of the class – including calling its methods – should be replaced with the suggested alternative.

How to fix it #

Replace the usage of the deprecated class with its recommended replacement.

 <?php declare(strict_types = 1);
 
-$logger = new OldLogger();
+$logger = new NewLogger();
 $logger->log('hello');

How to ignore this error #

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

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

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.