Menu

← Back to generics.*

Error Identifier: generics.deprecatedClassDefault

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 NewFormatter instead */
class OldFormatter
{
}

/**
 * @template T = OldFormatter
 */
class Pipeline
{
}

This error is reported by the phpstan-deprecation-rules extension.

Why is it reported? #

A @template tag uses a deprecated class as its default type value. The @template T = DefaultClass syntax specifies a default type for a generic parameter, but when DefaultClass is deprecated, the generic class creates a dependency on a class planned for removal. Any usage of Pipeline without an explicit type argument would implicitly use the deprecated OldFormatter.

In the example above, the template parameter T defaults to OldFormatter, which is marked as @deprecated.

How to fix it #

Replace the deprecated default type with the recommended replacement:

 <?php declare(strict_types = 1);
 
 /**
- * @template T = OldFormatter
+ * @template T = NewFormatter
  */
 class Pipeline
 {
 }

Alternatively, remove the default if there is no suitable non-deprecated replacement:

 <?php declare(strict_types = 1);
 
 /**
- * @template T = OldFormatter
+ * @template T
  */
 class Pipeline
 {
 }

How to ignore this error #

You can use the identifier generics.deprecatedClassDefault to ignore this error using a comment:

// @phpstan-ignore generics.deprecatedClassDefault
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: generics.deprecatedClassDefault

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.