Menu

← Back to requireExtends.*

Error Identifier: requireExtends.class

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 InvalidUsage // ERROR: PHPDoc tag @phpstan-require-extends is only valid on trait or interface.
{
}

Why is it reported? #

The @phpstan-require-extends PHPDoc tag is used on a class, but this tag is only valid on traits and interfaces. The tag is designed to constrain which classes can use a trait or implement an interface by requiring them to extend a specific base class. Using it on a class itself does not make sense because a class already defines its own inheritance.

How to fix it #

If the intent is to constrain trait users, move the tag to a trait:

 <?php declare(strict_types = 1);
 
 /**
  * @phpstan-require-extends SomeClass
  */
-class InvalidUsage
+trait RequiresSomeClass
 {
 }

If the intent is to constrain interface implementations, move the tag to an interface:

 <?php declare(strict_types = 1);
 
 /**
  * @phpstan-require-extends SomeClass
  */
-class InvalidUsage
+interface RequiresSomeClass
 {
 }

If the class should simply extend the specified class, use the extends keyword:

 <?php declare(strict_types = 1);
 
-/**
- * @phpstan-require-extends SomeClass
- */
-class InvalidUsage
+class ValidUsage extends SomeClass
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\PhpDoc\RequireExtendsDefinitionClassRule [1]
  • PHPStan\Rules\PhpDoc\RequireExtendsDefinitionTraitRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.