Menu

← Back to requireExtends.*

Error Identifier: requireExtends.enum

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

enum Suit: string
{
	case Hearts = 'hearts';
	case Diamonds = 'diamonds';
}

/**
 * @phpstan-require-extends Suit
 */
trait CardTrait // ERROR: PHPDoc tag @phpstan-require-extends cannot contain non-class type Suit.
{
}

Why is it reported? #

The @phpstan-require-extends PHPDoc tag is used on traits and interfaces to require that any class using the trait (or implementing the interface) must extend a specific class. However, this tag can only reference a class – not an enum, interface, or trait.

Enums cannot be extended in PHP, so requiring a class to extend an enum is impossible and makes no sense.

How to fix it #

Replace the enum reference with a class, or use @phpstan-require-implements if the intent is to require implementing an interface:

 <?php declare(strict_types = 1);
 
-/**
- * @phpstan-require-extends Suit
- */
+/**
+ * @phpstan-require-implements HasSuit
+ */
 trait CardTrait
 {
 }

If the trait should only be used by classes extending a specific parent class:

 <?php declare(strict_types = 1);
 
+abstract class Card
+{
+}
+
 /**
- * @phpstan-require-extends Suit
+ * @phpstan-require-extends Card
  */
 trait CardTrait
 {
 }

How to ignore this error #

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

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

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.