Skip to content

Wrap the closure return type in withFreshQueryLog() - #61444

Open
SanderMuller wants to merge 1 commit into
laravel:13.xfrom
SanderMuller:closure-return-type-parens
Open

Wrap the closure return type in withFreshQueryLog()#61444
SanderMuller wants to merge 1 commit into
laravel:13.xfrom
SanderMuller:closure-return-type-parens

Conversation

@SanderMuller

Copy link
Copy Markdown
Contributor

withFreshQueryLog() is annotated:

@param  (\Closure(): array{query: string, bindings: array, time: float|null}[])  $callback

No phpdoc standard settles whether that trailing [] belongs to the return type or to the whole closure. PHPStan binds it to the return type, so $callback is a closure returning a list of log entries. Mago, another static analyser, binds it to the closure and reads $callback as an array of closures. That contradicts the method's own @return array{...}[] and the body doing $result = $callback().

Wrapping the return type in parentheses says which one was meant, and both analysers then agree. PHPStan's inference does not change. I ran both forms and each gives:

Closure(): array<array{query: string, bindings: array, time: float|null}>

Mago's maintainer suggested this form for the same reason, since neither analyser can change its precedence without breaking its own users: carthage-software/mago#2310

This is the only annotation of this shape in the framework.

@SanderMuller
SanderMuller force-pushed the closure-return-type-parens branch from 39ac2e8 to 906167c Compare September 5, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant