PHP TypeLang Help

@var

@var is the most flexible of the type tags: it documents the type of a property, a class constant, or — written inline, right above an assignment — a local variable at the point it is declared or reassigned. That last form is especially useful for narrowing a variable's type where PHP or a static analyzer would otherwise infer something too broad, such as right after decoding JSON or pulling a value out of an untyped array.

"@var" <Type> [ <Variable> ] [ <Description> ]

The variable name is optional and mainly exists to disambiguate which of several variables mentioned on the same line the type applies to; on a property or constant, where there is only ever one target, it is normally left out entirely.

Parsing a @var tag produces a VarTag instance exposing:

  • $type — the documented TypeNode.

  • $variable — the name after the type, without the leading $, or null when none was written. Unlike @param, whose $variable is always present, @var's is nullable because the name is optional in the grammar.

final class VarTag extends TypedTag { public function __construct( string $name, TypeReference $statement, public readonly ?string $variable = null, ?DescriptionInterface $description = null, ) { parent::__construct( $name, $statement, $description, ); } }

Defined by the PSR-19 draft (FIG proposed PHPDoc Tags, §5.18) and by phpDocumentor.

05 July 2026