Menu

← Back to generics.*

Error Identifier: generics.interfaceConflict

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 Repository
{
}

/** @extends Repository<string> */
interface StringRepository extends Repository
{
}

/** @extends Repository<int> */
interface IntRepository extends Repository
{
}

/** @implements Repository<string> */
class MyClass implements StringRepository, IntRepository
{
}

Why is it reported? #

A class or interface specifies conflicting type arguments for the same generic interface through different inheritance paths. When a class implements or extends the same generic interface multiple times (through different parent interfaces or classes), the template type arguments must be identical.

In the example above, MyClass implements both StringRepository (which extends Repository<string>) and IntRepository (which extends Repository<int>). This creates a conflict because Repository cannot be parameterized with both string and int at the same time.

How to fix it #

Ensure all inheritance paths specify the same type arguments for the shared interface:

 <?php declare(strict_types = 1);
 
-/** @extends Repository<int> */
-interface IntRepository extends Repository
+/** @extends Repository<string> */
+interface AnotherStringRepository extends Repository
 {
 }

 /** @implements Repository<string> */
-class MyClass implements StringRepository, IntRepository
+class MyClass implements StringRepository, AnotherStringRepository
 {
 }

Or restructure the class hierarchy to avoid implementing the same generic interface with different type arguments.

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.