website/errors/selfOut.trait.md
<?php declare(strict_types = 1);
trait MyTrait
{
}
class MyClass
{
use MyTrait;
/**
* @phpstan-self-out MyTrait
*/
public function apply(): void
{
}
}
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.
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
{
}
}