PHP Generics Today
summary
Explains that PHP already supports generics via docblock @template annotations consumed by static analyzers like Psalm and PHPStan, showing concrete examples: typed arrays/collections, a generic Queue (add/getNext), a mirror function that preserves T, and Laravel’s app(Class::class) using class-string<T> to return T. Runtime checks are absent, so CI must include static analysis. A recent RFC for partial language support fails, but the docblock approach is used successfully in production.
AI-written summary · about
chapters (12)
- 0:00Introduction of speaker
- 1:18Why types matter in PHP
- 5:10Limitations of PHP type system
- 6:23Type hints vs type declarations
- 9:50Introducing generics concept
- 13:23Generics in functions
- 15:17Generics with interfaces
- 19:56Real-world generics example
- 23:06Benefits of generics in PHP
- 25:04Language support for generics
- 28:21Summary and future outlook
- 28:44Q&A session








