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.

PDF delivered to your inbox after checkout.

Almost Generics in PHP book cover

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

01

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.

02

The proposal, decoded

A plain-language walkthrough of monomorphization, type bounds, invariance, and what is and is not in scope for the first version.

03

Hands-on examples

Real code using the PHPAlgorithms library - ArrayList<T>, generic containers, typed collections - so you can see how it works in practice.

04

Testing strategies

How to test generic abstractions across type variations. Static analysis, representative runtime tests, and property-based testing approaches.

05

Design pattern impact

How Strategy, Abstract Factory, and other common patterns change under compile-time generics. Cleaner domain policies through the type system.

06

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 PHP
    What generics are, why they matter, and the state of PHP without them.
  • Chapter 2
    From Wish List to Proposal
    The full timeline from the mid-2000s to the PHP Foundation’s 2025 RFC.
  • Chapter 3
    Inside the Compile-Time Generics Proposal
    Monomorphization, what is in scope, what is not, and why.
  • Chapter 4
    Exploring Generics via the Proposal
    Practical examples from the PHPAlgorithms open-source library.
  • Chapter 5
    Testing and Validation of Generic Code
    Static analysis, runtime tests, property-based testing for generic abstractions.
  • Chapter 6
    Constraints, Variance, and Type Safety
    Bounded type parameters, invariance rules, and what is valid or unsafe.
  • Chapter 7
    Impact on Design Patterns
    Strategy, Abstract Factory, and other patterns reimagined with generics.
  • Chapter 8
    Open Questions and Controversies
    The debates from PHP Internals: scope, variance, tooling, and collections.
  • Chapter 9
    What It Would Mean for PHP’s Future
    Earlier 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

Doğan Uçar

Doğan Uçar

Senior PHP engineer with 10+ years building production systems. Creator of PHPAlgorithms, the open-source library used for the hands-on examples throughout this book. Consultant at Ucar Solutions UG. Writing and thinking about PHP’s type system since the language introduced its first serious type annotations.

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.