# [Pre-RFC] Reified generics

- Thread: https://externals.io/message/132178
- Original archive: https://news-web.php.net/php.internals/132178
- Started by Barel on 2026-08-06T09:00:42+00:00
- Messages: 7
- RFC: Bound-Erased Generic Types (Declined) — https://externals.io/rfc/bound_erased_generic_types.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #132178 — Barel — 2026-08-06T09:00:42+00:00

URL: https://externals.io/message/132178#132178

Hi,

In this RFC https://wiki.php.net/rfc/bound_erased_generic_types Seifeddine
Gmati proposed bound-erased generics for PHP. The RFC did not pass mainly
because people thought that, if later on reified generics were added on top
of this, there would be BC breaks for code that was not type checked and
then started to be type checked. To try to avoid this objection, Rob
Landers implemented an experimental reified version of generics on top of
Seifeddine's proposal.

There was very little discussion about this proposal because Seifeddine put
the RFC to vote very soon after Rob sent it. I think that this was a very
valid proposal that should have been explored in more detail. What I have
tried to do is to bring this proposal forward and make it complete.

This is the branch where you can find my implementation (it's based on
Rob's branch): https://github.com/carlos-granados/php-src/tree/reify

I wrote a document about all the changes and the findings:
https://github.com/carlos-granados/php-src/blob/reify/docs/source/core/reify.md

Looking forward to your thoughts, comments and suggestions

Cheers

Carlos

---

## #132179 — Rob Landers — 2026-08-06T09:40:34+00:00

URL: https://externals.io/message/132178#132179 · In reply to: #132178

> Hi,
> 
> In this RFC https://wiki.php.net/rfc/bound_erased_generic_types Seifeddine Gmati proposed bound-erased generics for PHP. The RFC did not pass mainly because people thought that, if later on reified generics were added on top of this, there would be BC breaks for code that was not type checked and then started to be type checked. To try to avoid this objection, Rob Landers implemented an experimental reified version of generics on top of Seifeddine's proposal.
> 
> There was very little discussion about this proposal because Seifeddine put the RFC to vote very soon after Rob sent it. I think that this was a very valid proposal that should have been explored in more detail. What I have tried to do is to bring this proposal forward and make it complete.
> 
> This is the branch where you can find my implementation (it's based on Rob's branch): https://github.com/carlos-granados/php-src/tree/reify
> 
> I wrote a document about all the changes and the findings: https://github.com/carlos-granados/php-src/blob/reify/docs/source/core/reify.md
> 
> Looking forward to your thoughts, comments and suggestions
> 
> Cheers
> 
> Carlos

Hi Carlos,

You really should have reached out instead of a working in isolation. Join us in discord, the proposal is delayed until September-ish.

— Rob

---

## #132180 — Barel — 2026-08-06T09:45:54+00:00

URL: https://externals.io/message/132178#132180 · In reply to: #132179

>
>
>
> Hi Carlos,
>
> You really should have reached out instead of a working in isolation. Join
> us in discord, the proposal is delayed until September-ish.
>
> — Rob
>

I have no idea where that discord is, can you point me to it?

Cheers

Carlos

---

## #132181 — Rob Landers — 2026-08-06T09:49:18+00:00

URL: https://externals.io/message/132178#132181 · In reply to: #132180

> > […]
> 
> I have no idea where that discord is, can you point me to it?
> 
> Cheers
> 
> Carlos 

https://discord.com/channels/356354025865740288/970793312791445514 or https://discord.com/channels/356354025865740288/1507404597571092590

— Rob

---

## #132182 — Barel — 2026-08-06T09:53:27+00:00

URL: https://externals.io/message/132178#132182 · In reply to: #132181

>
>
> 
>
>
> Hi Carlos,
>
> You really should have reached out instead of a working in isolation. Join
> us in discord, the proposal is delayed until September-ish.
>
> — Rob
>
>
> I have no idea where that discord is, can you point me to it?
>
> Cheers
>
> Carlos
>
>
> https://discord.com/channels/356354025865740288/970793312791445514 or
> https://discord.com/channels/356354025865740288/1507404597571092590
>
> — Rob
>

Rob,

Thanks, it seems that to join a channel I also need to know the server
where It lives (I've never used Discord much before). Can you share this
info as well?

Cheers

Carlos

---

## #132183 — Larry Garfield — 2026-08-06T15:43:45+00:00

URL: https://externals.io/message/132178#132183 · In reply to: #132182

> Thanks, it seems that to join a channel I also need to know the server 
> where It lives (I've never used Discord much before). Can you share 
> this info as well?
>
> Cheers
>
> Carlos

https://phpc.chat/

The PHP Community chat is unofficial, but lately it's where the big names are hanging out, including a lot of Internals regulars.  Beware, the Internals channel is annoyingly noisy and has a hard time staying on topic. :-)

--Larry Garfield

---

## #132195 — Alexander Lisachenko — 2026-08-10T10:16:01+00:00

URL: https://externals.io/message/132178#132195 · In reply to: #132183

Hello, internals!

Want to share some proof-of-concept and ideas regarding the Php Generics.
I've recreated the memoization generics as a user-land library
https://github.com/lisachenko/userland-php-generics, installable as a
simple composer package to check the concept itself and see where we have
limits now.

What I discovered - that a significant part of the core is suitable to
define generics *and keep the opcode arrays shared *between all
concrete memoized versions with different types:

I tried to deep-clone a template's zend_class_entry under a new name and
rewrited only the zend_type of its properties, parameters and return
types while sharing the compiled method bodies through the engine's own
op_array refcount. Thus, cost of a specialization is about
sizeof(zend_op_array) per method, independent of how large those methods
are, rather than a full copy of the opcodes.

Best regards,
Alexander

чт, 6 авг. 2026 г. в 18:46, Larry Garfield <larry@garfieldtech.com>:

> 
>
> > […]
>
> https://phpc.chat/
>
> The PHP Community chat is unofficial, but lately it's where the big names
> are hanging out, including a lot of Internals regulars.  Beware, the
> Internals channel is annoyingly noisy and has a hard time staying on topic.
> :-)
>
> --Larry Garfield
