Generics (in PHP)
summary
Claim: generics bring precise typing and IDE support to PHP today via annotations rather than core language changes. Uses @template plus @implements/@extends and class-string to get type-safe factories, collection patterns and deserialization autocompletion, with PhpStorm, VS Code, PHPStan and Psalm enforcing checks and no runtime overhead. Core PHP lacks native generics because of C internals and performance concerns, but Symfony already annotates many components (security, serializer, DI) and annotations reliably catch mismatches at analysis time.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 2:30What are generics
- 5:04Main use cases
- 9:43Generics in other languages
- 15:13PHP generics state
- 18:30Workarounds in PHP
- 21:33Generics annotations
- 28:46Co- and contravariance
- 33:29PHP tools support
- 36:50Symfony generics
- 40:25Conclusion








