Menu

Error Identifier: selfOut.trait

← Back to selfOut.*

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 MyTrait
{
}

class MyClass
{
	use MyTrait;

	/**
	 * @phpstan-self-out MyTrait
	 */
	public function apply(): void
	{
	}
}

Why is it reported? #

The @phpstan-self-out PHPDoc tag references a trait. Traits cannot be used in type declarations or type operations because they are not types in PHP’s type system. They are a code reuse mechanism and cannot appear in instanceof checks, type hints, or intersection types at runtime. Using a trait in @phpstan-self-out does not produce a meaningful type.

How to fix it #

Replace the trait with an interface that describes the contract:

-trait MyTrait
+interface MyInterface
 {
 }

 class MyClass
 {
-	use MyTrait;
+	use SomeTrait;

 	/**
-	 * @phpstan-self-out MyTrait
+	 * @phpstan-self-out self&MyInterface
 	 */
 	public function apply(): void
 	{
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Functions\ExistingClassesInArrowFunctionTypehintsRule [1]
  • PHPStan\Rules\Functions\ExistingClassesInClosureTypehintsRule [1]
  • PHPStan\Rules\Functions\ExistingClassesInTypehintsRule [1]
  • PHPStan\Rules\Methods\ExistingClassesInTypehintsRule [1]
  • PHPStan\Rules\Properties\ExistingClassesInPropertyHookTypehintsRule [1]
Theme
A
© 2026 PHPStan s.r.o.