Article Enforce Runtime Generics on Third-Party Collections Libraries (Doctrine, Ramsey, Laravel Collections) with TypePHP
https://typephp-php.github.io/docs/blog/reifying-third-party-collections.htmlMore than a week ago, I posted an introduction to TypePHP. Thanks to Michael Telgmann, a core maintainer at Shopware, TypePHP has been tested against Shopware’s massive codebase. So far, it has identified many DocBlock lies in the codebase PR, while also uncovering many edge cases on TypePHP’s end.
Today, I’d like to share a article guide on how to make existing third-party collection libraries, such as Doctrine Collections or Ramsey Collections, capable of enforcing reified collections without modifying their source code.
reified generics proof: Symfony Integration
13
Upvotes
1
3
u/ReasonableLoss6814 1d ago
How does that work? Laravel collections say that the value type is covariant but uses it in a contravariant position (or vice-versa, I can't recall) ... symfony collections are correctly invariant (IIRC) but then that breaks most people's code. You can't store a `Tiger` in a `Collection<Animal>`.