Menu

← Back to requireImplements.*

Error Identifier: requireImplements.trait

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

trait SomeTrait
{
}

/**
 * @phpstan-require-implements SomeTrait
 */
trait MyTrait
{
}

Why is it reported? #

The @phpstan-require-implements PHPDoc tag contains a type that is a trait instead of an interface. This tag is used on traits to enforce that any class using the trait must implement a specific interface. Since traits cannot be implemented (only used), referencing a trait in @phpstan-require-implements is invalid.

How to fix it #

Replace the trait reference with an interface:

-/**
- * @phpstan-require-implements SomeTrait
- */
+/**
+ * @phpstan-require-implements SomeInterface
+ */
 trait MyTrait
 {
 }

If the goal is to ensure that classes using this trait also use another trait, there is no PHPDoc tag for that. Consider documenting the requirement in a comment or restructuring the code to use an interface instead.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\PhpDoc\RequireImplementsDefinitionTraitRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.