For PHP developers who want to stay ahead
Almost Generics in PHP
A guided journey through the PHP Foundation’s compile-time generics proposal. History, design decisions, hands-on examples, and what it means for the future of PHP type safety.
Also available on Amazon (Kindle & paperback)
PHP is getting generics. Are you ready?
The PHP Foundation published its compile-time generics proposal in August 2025. For most developers, the announcement raised more questions than it answered. What exactly are compile-time generics? How do they differ from what other languages do? What can you actually build with them?
This book answers all of that. It covers the history, the technical design, the trade-offs, and the practical patterns - so when generics ship, you can use them effectively from day one.
What you will learn
The full history
Why generics have been requested in PHP since the mid-2000s, why they never shipped, and what makes the current moment different.
The proposal, decoded
A plain-language walkthrough of monomorphization, type bounds, invariance, and what is and is not in scope for the first version.
Hands-on examples
Real code using the PHPAlgorithms library - ArrayList<T>, generic containers, typed collections - so you can see how it works in practice.
Testing strategies
How to test generic abstractions across type variations. Static analysis, representative runtime tests, and property-based testing approaches.
Design pattern impact
How Strategy, Abstract Factory, and other common patterns change under compile-time generics. Cleaner domain policies through the type system.
The open questions
Scope debates, variance limitations, tooling readiness (Psalm, PHPStan), and what the community is still figuring out - so you can form your own view.
Inside the book
-
Chapter 1
The Dream of Generics in PHPWhat generics are, why they matter, and the state of PHP without them.
-
Chapter 2
From Wish List to ProposalThe full timeline from the mid-2000s to the PHP Foundation’s 2025 RFC.
-
Chapter 3
Inside the Compile-Time Generics ProposalMonomorphization, what is in scope, what is not, and why.
-
Chapter 4
Exploring Generics via the ProposalPractical examples from the PHPAlgorithms open-source library.
-
Chapter 5
Testing and Validation of Generic CodeStatic analysis, runtime tests, property-based testing for generic abstractions.
-
Chapter 6
Constraints, Variance, and Type SafetyBounded type parameters, invariance rules, and what is valid or unsafe.
-
Chapter 7
Impact on Design PatternsStrategy, Abstract Factory, and other patterns reimagined with generics.
-
Chapter 8
Open Questions and ControversiesThe debates from PHP Internals: scope, variance, tooling, and collections.
-
Chapter 9
What It Would Mean for PHP’s FutureEarlier failure detection, less boilerplate, and PHP’s long-term positioning.
Who this book is for
PHP developers building large systems
If you work on codebases where type drift, unclear interfaces, or runtime surprises cost you real time, this book explains exactly how generics will help - and what they will not solve.
Developers coming from typed languages
If you know generics from Java, C#, or TypeScript and want to understand the PHP approach, this book maps the differences and explains the design choices behind the compile-time model.
PHP Foundation article readers
If you read the Foundation’s “Compile-time generics: yay or nay?” and wanted more depth, this book is the extended companion. Every section of the proposal is covered in detail.
Engineers who want to stay ahead
Generics will change how PHP is written. Understanding them before they ship - the rationale, the trade-offs, the patterns - means you can adopt them effectively instead of catching up later.
About the author
Get the PDF now
Buy direct for €17.99 and the PDF lands in your inbox. No account needed.
Prefer Amazon? Get the Kindle or paperback edition for €21.28.