Menu

← Back to requireExtends.*

Error Identifier: requireExtends.onClass

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

/**
 * @phpstan-require-extends SomeClass
 */
class InvalidClass
{
}

Why is it reported? #

The @phpstan-require-extends PHPDoc tag is placed on a class. This tag is only valid on traits and interfaces. On a trait, it ensures that any class using the trait extends a specific base class. On an interface, it ensures that implementing classes extend a specific base class. Using it on a regular class has no effect and indicates a mistake.

How to fix it #

Remove the @phpstan-require-extends tag from the class:

-/**
- * @phpstan-require-extends SomeClass
- */
 class InvalidClass
 {
 }

If the constraint is intended, move it to a trait or interface where @phpstan-require-extends is valid:

 /**
  * @phpstan-require-extends SomeClass
  */
-class InvalidClass
+interface MyInterface
 {
 }

How to ignore this error #

You can use the identifier requireExtends.onClass to ignore this error using a comment:

// @phpstan-ignore requireExtends.onClass
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: requireExtends.onClass

Rules that report this error #

  • PHPStan\Rules\PhpDoc\RequireExtendsDefinitionClassRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.