Menu

← Back to requireImplements.*

Error Identifier: requireImplements.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);

class SomeClass
{
}

/**
 * @phpstan-require-implements SomeClass
 */
trait MyTrait // ERROR: PHPDoc tag @phpstan-require-implements cannot contain non-interface type SomeClass.
{
}

Why is it reported? #

The @phpstan-require-implements PHPDoc tag is used on traits to declare that any class using the trait must implement a specific interface. However, the tag references a class instead of an interface. Since classes are not “implemented” but “extended”, this is not a valid use of @phpstan-require-implements.

How to fix it #

If the trait should require that the using class extends a specific class, use @phpstan-require-extends instead:

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

If the trait should require that the using class implements a specific interface, reference an interface:

 <?php declare(strict_types = 1);
 
+interface SomeInterface
+{
+}
+
 /**
- * @phpstan-require-implements SomeClass
+ * @phpstan-require-implements SomeInterface
  */
 trait MyTrait
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\PhpDoc\RequireImplementsDefinitionTraitRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.