Menu

← Back to generics.*

Error Identifier: generics.noParent

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
 * @template U of \Exception
 */
class Collection
{
}

/**
 * @extends Collection<int, \InvalidArgumentException>
 */
class FooDoesNotExtendAnything
{
}

Why is it reported? #

The class has an @extends PHPDoc tag specifying generic type arguments for Collection, but it does not actually extend any class. The @extends tag is meaningless without a corresponding extends clause in the class declaration.

The same applies to @implements tags on classes that do not implement the referenced interface, and @use tags on classes that do not use the referenced trait.

How to fix it #

Add the missing extends clause:

 /**
  * @extends Collection<int, \InvalidArgumentException>
  */
-class FooDoesNotExtendAnything
+class FooDoesNotExtendAnything extends Collection
 {
 }

Or remove the unnecessary @extends tag if the class is not supposed to extend Collection:

-/**
- * @extends Collection<int, \InvalidArgumentException>
- */
 class FooDoesNotExtendAnything
 {
 }

How to ignore this error #

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

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

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.