Skip to content

Tag reference

@use

Traits can be generic too, and PHP’s use keyword for pulling a trait into a class carries no syntax for type arguments. @use supplies them, mirroring what @extends does for parent classes and @implements does for interfaces — for example a caching trait that needs to know what kind of value it is caching.

Grammar

"@phpstan-use" <Type> [ <Description> ]
"@psalm-use" <Type> [ <Description> ]
"@use" <Type> [ <Description> ]
"@template-use" <Type> [ <Description> ]

Examples

Binding a generic caching trait's value type.
final class ProductRepository
{
/** @use Cacheable<Product> */
use Cacheable;
}
Binding a comparable trait to the class it is mixed into.
final class Money
{
/** @use ComparableTrait<Money> */
use ComparableTrait;
}

Names by platform

phpstan
@phpstan-use
psalm
@psalm-use
standard
@use@template-use

Parsing a @use tag produces a tag exposing $type — the TypeNode naming the trait with its type arguments — along with the inherited $name and $description.

final class UseTag extends InheritanceTag
{
// adds nothing of its own: `$type`, `$name`
// and `$description` are inherited.
}

The alias @template-use is also recognized and parses to the same UseTag instance. See also @extends and @implements for the equivalent tags used on a generic parent class or interface.