Tag reference
@param-closure-this
The @param-closure-this tag documents what $this refers to inside a
Closure parameter. A @param on that same parameter already
describes the closure’s own signature — the arguments it receives and what
it returns — but says nothing about the object it will be bound to when the
closure is eventually invoked through Closure::bindTo(), Closure::call(),
or an equivalent internal rebinding. Without this tag, code inside the
closure that reads $this has no documented type to check against.
Grammar
"@param-closure-this" <Type> <Variable> [ <Description> ]"@phpstan-param-closure-this" <Type> <Variable> [ <Description> ]Examples
/** * @param Closure(): string $formatter * @param-closure-this Builder $formatter */function withFormatter(Closure $formatter): static/** * @param Closure(int): void $callback * @param-closure-this Connection $callback Bound before dispatch so * the callback can reach the connection's * protected members. */function onConnect(Closure $callback): voidNames by platform
- phpstan
@phpstan-param-closure-this- standard
@param-closure-this
Parsing a @param-closure-this tag produces a ParamClosureThisTag instance
(a TypedVariableTag) exposing:
$type— the documentedTypeNodethat$thisis bound to.$variable— the closure parameter’s name, without the leading$.
final class ParamClosureThisTag extends TypedVariableTag{ // Own constructor adds nothing; both // properties below are inherited from // TypedVariableTag (and its parent TypedTag):
public readonly TypeNode $type;
public readonly string $variable;}This is the same shape as @param, just aimed at the closure’s binding rather than its signature.
PHPStan documents @param-closure-this
alongside its other callable-related tags; Psalm has no equivalent.