Tag reference
@extends
When a class extends a generic parent — one that declares its own
@template type parameters — plain PHP inheritance has no
way to say what those parameters resolve to in the subclass. @extends fills
that gap by supplying the concrete (or still-generic) type arguments for the
parent, so that a static analyzer can follow the type all the way down the
hierarchy.
Grammar
"@extends" <Type> [ <Description> ]"@inherits" <Type> [ <Description> ]"@phan-extends" <Type> [ <Description> ]"@phan-inherits" <Type> [ <Description> ]"@phpstan-extends" <Type> [ <Description> ]"@psalm-extends" <Type> [ <Description> ]"@template-extends" <Type> [ <Description> ]Examples
/** * @extends Collection<User> */final class UserCollection extends Collection {}/** * @template T * @extends Repository<T> */abstract class BaseRepository extends Repository {}Names by platform
- phan
@phan-extends@phan-inherits- phpstan
@phpstan-extends- psalm
@psalm-extends- standard
@extends@inherits@template-extends
Parsing an @extends tag produces a tag exposing $type — the parsed
TypeNode describing the parent with its type arguments — alongside the
$name and $description every tag carries.
final class ExtendsTag extends InheritanceTag{ // adds nothing of its own: the // `public readonly TypeNode $type` is // inherited from TypedTag, which in turn // keeps the protected TypeReference // $statement it was built from.}This component also registers two alternative spellings,
@inherits and
@template-extends, that some tools use in
place of @extends; parsing either one produces the exact same kind
of tag. See also @implements and
@use for the equivalent tags on interfaces and traits.
@extends is not a phpDocumentor or PSR-19 tag. It is a generics
convention introduced independently by
PHPStan and
Psalm,
and this component follows their lead rather than any formal
standard.