rfc:bound_erased_generic_types
PHP RFC: Bound-Erased Generic Types
- Version: 0.1
- Date: 2026-05-06
- Author: Seifeddine Gmati, azjezz@carthage.software
- Status: Draft
Introduction
This RFC proposes adding generic type syntax to PHP. Type parameters declared on classes, interfaces, traits, functions, methods, closures, and arrow functions are erased to their declared bounds at compile time: the runtime enforces the bound, while parametricity is verified by static analysis tools. Type information that today lives in @template and @param Container<int> docblocks becomes first-class language syntax, exposed through a new Reflection API.
<?php final readonly class Box<+T: mixed> { public function __construct( public T $value, ) {} public function zip<O>(O $value): self<Pair<T, O>> { return new self(new Pair($this->value, $value)); } } function first<T>(array<T> $items): ?T { return $items[0] ?? null; } $box = new Box::<string>("hello, world");
Proposal
TBD.
Examples
TBD.
Backward Incompatible Changes
TBD.
Proposed PHP Version(s)
Next PHP 8.x.
RFC Impact
To the Ecosystem
TBD.
To Existing Extensions
TBD.
To SAPIs
TBD.
Open Issues
None at this time.
Future Scope
TBD.
Voting Choices
TBD.
Patches and Tests
TBD.
Implementation
TBD.
References
TBD.
Rejected Features
None at this time.
Changelog
- 2026-05-06: Initial draft.
rfc/bound_erased_generic_types.txt · Last modified: by azjezz