Menu

← Back to generics.*

Error Identifier: generics.notCompatible

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

/**
 * @template T
 */
interface Collection
{
}

/**
 * @implements int
 */
class NumberList implements Collection
{
}

Why is it reported? #

The @implements, @extends, or @use PHPDoc tag specifies a type that is not a valid generic type for the referenced class or interface. The type in the tag must be a generic type like Collection<int>, not a plain type like int. PHPStan expects the tag to match the generic signature of the parent class or interface.

How to fix it #

Use the correct generic type syntax in the PHPDoc tag:

 /**
- * @implements int
+ * @implements Collection<int>
  */
 class NumberList implements Collection
 {
 }

If the parent class or interface has multiple template parameters, specify all of them:

 /**
- * @implements Map<string>
+ * @implements Map<string, int>
  */
 class StringIntMap implements Map
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Generics\ClassAncestorsRule [1]
  • PHPStan\Rules\Generics\EnumAncestorsRule [1]
  • PHPStan\Rules\Generics\InterfaceAncestorsRule [1]
  • PHPStan\Rules\Generics\UsedTraitsRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.