#2934·phpstan

Generic types don't work for closures?

Author: enumagCreated Jan 31, 2020Updated Sep 27, 2026
Labelsfeature-request

Bug report

I encountered this with Doctrine collections and simplified it to reproduce in phpstan.org. Based on the @template annotations, I think PHPStan should be aware that the closure returns an object of the same class as given to it and the collection is of a valid type.

Code snippet that reproduces the problem

https://phpstan.org/r/fc709263-e2d3-43ef-a253-047b1152a532 edit: https://phpstan.org/r/22a82b0c-839a-4242-82d5-0aab21e5f1c0

Expected output

no error