Tag reference
@method
The @method tag declares a “magic” method: one that a class makes callable
through __call() or __callStatic() rather than through an ordinary method
declaration, and that therefore does not otherwise appear anywhere in the
class’s own source. It is written on the class itself, once per magic method,
using the same syntax as a callable type.
Grammar
"@method" [ "static" ] ( <Type> <CallableType> | <CallableType> ) [ <Description> ]"@phan-method" [ "static" ] ( <Type> <CallableType> | <CallableType> ) [ <Description> ]"@phpstan-method" [ "static" ] ( <Type> <CallableType> | <CallableType> ) [ <Description> ]"@psalm-method" [ "static" ] ( <Type> <CallableType> | <CallableType> ) [ <Description> ]Examples
/** * @method void setName(string $name) */class Model {}/** * @method static static create(array $attributes) */class Model {}/** * @method int getId() * @method getId(): int */Names by platform
- phan
@phan-method- phpstan
@phpstan-method- psalm
@psalm-method- standard
@method
Parsing a @method tag produces a MethodTag instance:
final class MethodTag extends Tag{ public function __construct( string $name, public readonly CallableTypeNode $method, private readonly string $signature, public readonly bool $isStatic = false, ?DescriptionInterface $description = null, ) { parent::__construct($name, $description); }}It exposes:
$method— the declared signature (its name, parameters and return type) as aCallableTypeNode.$isStatic— whether the leading"static"keyword was present.
The constructor also keeps the signature exactly as
written in a $signature property, but that one is
private — it’s not part of the tag’s public shape, kept
internally only so the tag can render itself back to
source faithfully.
A return type written before the signature is folded into
$method’s own return type rather than kept separately,
so both forms shown above end up producing the same
$method value.
Defined by the PSR-19 draft and phpDocumentor’s own page.