Menu

Error Identifier: generics.notGeneric

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);

interface Foo
{
}

/**
 * @implements Foo<int>
 */
class Bar implements Foo // error: Foo is not generic
{
}

Why is it reported? #

A PHPDoc tag specifies generic type arguments for a class or interface that does not declare any @template tags. Since the referenced type is not generic, providing type parameters for it is meaningless and likely indicates a mistake.

This can happen in @extends, @implements, @use, @mixin, @param, @return, @var, @template bounds, and other PHPDoc tags.

How to fix it #

If the class or interface should be generic, add the @template tag to its definition:

 <?php declare(strict_types = 1);
 
+/**
+ * @template T
+ */
 interface Foo
 {
 }

 /**
  * @implements Foo<int>
  */
 class Bar implements Foo
 {
 }

If it is not meant to be generic, remove the type arguments from the PHPDoc tag:

 <?php declare(strict_types = 1);
 
 interface Foo
 {
 }

-/**
- * @implements Foo<int>
- */
 class Bar implements Foo
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Classes\LocalTypeAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitAliasesRule [1]
  • PHPStan\Rules\Classes\LocalTypeTraitUseAliasesRule [1]
  • PHPStan\Rules\Classes\MethodTagRule [1]
  • PHPStan\Rules\Classes\MethodTagTraitRule [1]
  • PHPStan\Rules\Classes\MethodTagTraitUseRule [1]
  • PHPStan\Rules\Classes\MixinRule [1]
  • PHPStan\Rules\Classes\MixinTraitRule [1]
  • PHPStan\Rules\Classes\MixinTraitUseRule [1]
  • PHPStan\Rules\Classes\PropertyTagRule [1]
  • PHPStan\Rules\Classes\PropertyTagTraitRule [1]
  • PHPStan\Rules\Classes\PropertyTagTraitUseRule [1]
  • PHPStan\Rules\Generics\ClassAncestorsRule [1]
  • PHPStan\Rules\Generics\ClassTemplateTypeRule [1]
  • PHPStan\Rules\Generics\EnumAncestorsRule [1]
  • PHPStan\Rules\Generics\FunctionTemplateTypeRule [1]
  • PHPStan\Rules\Generics\InterfaceAncestorsRule [1]
  • PHPStan\Rules\Generics\InterfaceTemplateTypeRule [1]
  • PHPStan\Rules\Generics\MethodTagTemplateTypeRule [1]
  • PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule [1]
  • PHPStan\Rules\Generics\MethodTemplateTypeRule [1]
  • PHPStan\Rules\Generics\TraitTemplateTypeRule [1]
  • PHPStan\Rules\Generics\UsedTraitsRule [1]
  • PHPStan\Rules\PhpDoc\FunctionAssertRule [1]
  • PHPStan\Rules\PhpDoc\IncompatibleClassConstantPhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePropertyHookPhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatiblePropertyPhpDocTypeRule [1]
  • PHPStan\Rules\PhpDoc\IncompatibleSelfOutTypeRule [1]
  • PHPStan\Rules\PhpDoc\InvalidPhpDocVarTagTypeRule [1]
  • PHPStan\Rules\PhpDoc\MethodAssertRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.