Menu

← Back to requireImplements.*

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

interface HasName
{
	public function getName(): string;
}

/**
 * @phpstan-require-implements HasName
 */
class MyClass
{
}

Why is it reported? #

The @phpstan-require-implements PHPDoc tag is only valid on traits. It tells PHPStan that any class using the trait must implement the specified interface. Placing this tag on a class or an enum has no effect and indicates a misunderstanding of the tag’s purpose.

How to fix it #

Move the tag to a trait:

 /**
  * @phpstan-require-implements HasName
  */
-class MyClass
+trait MyTrait
 {
 }

Or if the class should implement the interface, use implements directly:

-/**
- * @phpstan-require-implements HasName
- */
-class MyClass
+class MyClass implements HasName
 {
+	public function getName(): string
+	{
+		return 'name';
+	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\PhpDoc\RequireImplementsDefinitionClassRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.