Press enter or click to view image in full size
For more than a decade, PHP developers have debated one question:
Should PHP have generics?
Generics are a cornerstone feature in many languages — from Java and C# to TypeScript. They allow developers to write reusable, type-safe code without endless duplication. Yet in PHP, the road toward generics has been long, messy, and full of dead ends.
In 2025, the conversation took a major turn with the compile-time generics RFC. For the first time, the PHP community saw a realistic proposal that could bring generics into the language without compromising performance or backward compatibility.
That was so exciting — I decided to go on a journey to dive deep into the topic and its history and write about it. The result was not only a blog series here on Medium, but also my very first book. But let’s go one by one:
The Blog Series Recap
Earlier this year, I published a multi-part series exploring this journey in detail. Here’s the quick rundown:
Part 1: PHP Keeps Reaching for Generics — How “Compile-Time Generics” Might Finally Land
What the PHPFoundation proposed, how it is structured and what I think about it.
Part 2: From “Associated Types” to Manual Compile-Time Generics
From <T> annotations to static analysis hacks — how developers faked generics for years.
Part 3: Generics in PHP: Hands-On with Compile-Time Generics
A closer look at the 2025 proposal: monomorphization, syntax choices, and how it differs from runtime solutions.
Part 4: The Tricky Parts of PHP’s Compile-Time Generics (Variance, Traits, and Other Dragons)
Examples of repositories, collections, and service layers with generics — showing the practical benefits for real-world PHP.
Part 5: PHP Trying PHP’s Compile-Time Generics: From Sandbox to RFC Feedback
We searched for the generics in an official branch or similar and tried to simulate what it means to have generics on board.
Part 6: PHP Generics: The Ecosystem Impact of Compile-Time
The bigger picture: what happens when compile-time generics move from an experimental branch into mainstream PHP.
Part 7: PHP Generics: The Ecosystem Impact of Compile-Time
What could come after compile-time generics — and what lessons apply to PHP’s future?
Each part tackled one piece of the puzzle — and the response from readers was clear: this topic mattered.
Why a Book?
After finishing the series, I realized something: the story wasn’t complete. The series worked as a guided tour, but I felt a need of a single, structured resource — a place where history, RFC analysis, smaller examples, and design patterns all come together.
That’s why I wrote Generics in PHP — A Guided Journey Through the Compile-Time RFC.
It’s not just a reprint of the series. It’s the expanded, polished, and organized version — with additional chapters, refined examples, and insights into what generics mean for PHP developers today and tomorrow.
Get the Full Journey
If you enjoyed the series, you’ll find the book a natural next step.
📘 Generics in PHP — A Guided Journey Through the Compile-Time RFC is now available:
- Kindle Edition — quick and affordable.
- Paperback Edition — for those who like a reference on their desk.
Final Thought
The debate around generics in PHP is far from over. But whether the RFC passes tomorrow or evolves into something else, understanding the journey — and preparing for the future — makes you a stronger developer.
This book is my contribution to that conversation. I hope it helps you write cleaner, safer, and more expressive PHP.