Menu

Error Identifier: generics.notSubtype

← Back to generics.*

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 of \Countable */
class Collection
{
	/** @var list<T> */
	private array $items = [];
}

/** @var Collection<\stdClass> $c */
$c = new Collection();

Why is it reported? #

The type argument \stdClass provided to the generic type Collection is not a subtype of the template type’s bound \Countable. The class declares @template T of \Countable, which means any type argument must implement \Countable. Since \stdClass does not implement \Countable, it violates this constraint.

This ensures that generic types are used with compatible type arguments that satisfy the declared constraints.

How to fix it #

Use a type that satisfies the template bound:

-/** @var Collection<\stdClass> $c */
+/** @var Collection<\ArrayIterator<int, string>> $c */
 $c = new Collection();

Or if the bound is too restrictive, loosen it:

-/** @template T of \Countable */
+/** @template T of object */
 class Collection
 {
 	/** @var list<T> */
 	private array $items = [];
 }

How to ignore this error #

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

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

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]
Theme
A
© 2026 PHPStan s.r.o.