Skip to content

PHP RFC: Bound-Erased Generic Types#21969

Draft
azjezz wants to merge 19 commits intophp:masterfrom
carthage-software:rfc/bound-erased-generic-types
Draft

PHP RFC: Bound-Erased Generic Types#21969
azjezz wants to merge 19 commits intophp:masterfrom
carthage-software:rfc/bound-erased-generic-types

Conversation

@azjezz
Copy link
Copy Markdown

@azjezz azjezz commented May 6, 2026

azjezz added 13 commits May 6, 2026 06:09
Signed-off-by: azjezz <azjezz@protonmail.com>
Signed-off-by: azjezz <azjezz@protonmail.com>
Signed-off-by: azjezz <azjezz@protonmail.com>
… API

Signed-off-by: azjezz <azjezz@protonmail.com>
…resolve type-parameter refs

Signed-off-by: azjezz <azjezz@protonmail.com>
…atic, and parent

Signed-off-by: azjezz <azjezz@protonmail.com>
…antics

Signed-off-by: azjezz <azjezz@protonmail.com>
Signed-off-by: azjezz <azjezz@protonmail.com>
…litting)

Signed-off-by: azjezz <azjezz@protonmail.com>
…ectionClass

Signed-off-by: azjezz <azjezz@protonmail.com>
Signed-off-by: azjezz <azjezz@protonmail.com>
… error only at runtime use

Signed-off-by: azjezz <azjezz@protonmail.com>
azjezz added 2 commits May 6, 2026 21:05
…minal

Signed-off-by: azjezz <azjezz@protonmail.com>
…ce and reflection cleanup

Signed-off-by: azjezz <azjezz@protonmail.com>
Copy link
Copy Markdown
Member

@DanielEScherzer DanielEScherzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not even going to pretend like I understand this, or even read it all, but some initial notes, I hope you don't mind

I very much hope that this RFC gets to a point where it is voted on and hopefully passes, generics are great!

You may want to consider adding some kind of overview for how the implementation logic works (e.g. a new file in docs/source) to aid reviewers in understanding how all of the parts go together

You may want to also split this up, it currently adds support for

Classes, interfaces, traits, functions, methods, closures, and arrow functions

and an initial version might just support classes, interfaces, and methods. Just a thought, please don't take this as criticism - I really hope that something like this is added to PHP

Comment thread ext/reflection/php_reflection.stub.php Outdated
Comment thread ext/reflection/php_reflection.stub.php Outdated
Comment thread Zend/zend_ast.c Outdated
Comment thread Zend/zend_compile.c Outdated
Comment thread Zend/zend_compile.c Outdated
Comment thread Zend/zend_compile.c Outdated
Comment thread Zend/zend_compile.h Outdated
Comment thread Zend/zend_compile.h Outdated
Comment thread Zend/zend_extensions.h Outdated
Comment thread Zend/zend_modules.h Outdated
azjezz added 3 commits May 6, 2026 22:57
Signed-off-by: azjezz <azjezz@protonmail.com>
Signed-off-by: azjezz <azjezz@protonmail.com>
…lookups

Signed-off-by: azjezz <azjezz@protonmail.com>
@azjezz
Copy link
Copy Markdown
Author

azjezz commented May 6, 2026

Hi @DanielEScherzer

Thanks for the review!

On the internal docs: i'd lean toward holding off for now. If the RFC doesn't pass, we'd just throw the prose away; if it does, the API/internals will likely shift between now and acceptance, and I'd rather not rewrite the doc multiple times along the way. Once the RFC lands (hoping it does), I'm happy to write a proper INTERNALS section in one go against the final shape. or do you think there's value in having something now? (for review?)

Signed-off-by: azjezz <azjezz@protonmail.com>
@DanielEScherzer
Copy link
Copy Markdown
Member

Hi @DanielEScherzer

Thanks for the review!

On the internal docs: i'd lean toward holding off for now. If the RFC doesn't pass, we'd just throw the prose away; if it does, the API/internals will likely shift between now and acceptance, and I'd rather not rewrite the doc multiple times along the way. Once the RFC lands (hoping it does), I'm happy to write a proper INTERNALS section in one go against the final shape. or do you think there's value in having something now? (for review?)

I was thinking that this would be for reviewers to understand the rest of the patch - you know it best, since you wrote it, but others could use a roadmap/overview. I don't even known where to start for giving an example of "something like ..." for this, so I'll give one for #16952 (which I know best because I wrote it)

For supporting attributes on constants

  • the grammar for the language is adjust to allow attributes on constants, moving constant declarations into attributed_statement which can have (but doesn't need) attributes
  • the AST is stored in the same list of children as the constants in the declaration, as the last child
  • zend_compile_const_decl() will compile the attributes into a normal hashtable with zend_compile_attributes, and then emit a ZEND_DECLARE_ATTRIBUTED_CONST with a data znode where the data is a pointer to that table
  • at runtime, the VM handler will call zend_constant_add_attributes() to add the attributes

For supporting the deprecated attribute specifically

  • zend_constant_add_attributes() will flag the constant with CONST_DEPRECATED if the deprecated attribute is present
  • the existing logic to emit deprecation warnings for deprecated internal constants is instead replaced with calls to the new zend_deprecated_constant() function which handles reading for attributes if present

Just to have an understanding of how all of the pieces fit together

@azjezz
Copy link
Copy Markdown
Author

azjezz commented May 6, 2026

Makes sense. Will add it tomorrow morning 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants