Bound-Erased Generic Types

This RFC adds generic type syntax to PHP. Classes, interfaces, traits, functions, methods, closures, and arrow functions can declare type parameters; those parameters carry bounds, defaults, and variance markers; type arguments may be supplied at use sites and at call sites via turbofish.

final readonly class Pair<+L, +R> {
    public function __construct(
        public L $left,
        public R $right,
    ) {}
 
    public function swap(): Pair<R, L> {
        return new Pair($this->right, $this->left);
    }
}
 
final readonly class Box<+T> {
    public function __construct(
        public T $value,
    ) {}
 
    public function map<U>(callable $fn): Box<U> {
        return new Box(($fn)($this->value));
    }
 
    public function zip<O>(O $value): Box<Pair<T, O>> {
        return new Box(new Pair($this->value, $value));
    }
}
 
function identity<T>(T $value): T {
    return $value;
}
 
$greeting = new Box::<string>("hello, world");
$paired   = $greeting->zip::<int>(42);
$swapped  = $paired->value->swap();
$result   = identity::<Pair<int, string>>($swapped);
Click the bar to cast your vote!
98%
2%
1

Yes! Time to retire the non-spec docblocks

Share:
sandermuller-2 avatar
sandermuller-2
voted yes
1

I use them everywhere.

Share:
perer876 avatar
perer876
voted yes
1

Generics are a necessary feature for all modern languages. It can reduce so much clutter and is desperately needed.

Share:
keichinger avatar
keichinger
voted yes
1
Share:
michaelcontento avatar
michaelcontento
voted yes
1

after so many years, the seems like the least obtrusive way to add generics. Really hope to see it get accepted so we don't have to keep waiting. Seems like a no-brainer tbh.

Share:
neoighodaro avatar
neoighodaro
voted yes
1

.

Share:
baukevdw avatar
baukevdw
voted yes
1

It's an opportunity to modernize PHP.

Share:
vbsessa avatar
vbsessa
voted yes
1

This feature of native generics syntax in PHP is all I ever dream of..

Share:
rcalicdan avatar
rcalicdan
voted yes
1

This is the best of all worlds. Other generic approaches have been tried and never got too far.

Bound-Erased Generics gives us a chance to get a first-party syntax that will make developers happy, allow tooling like IDEs and static analysers to pick up on it, while still leaving the implementation open for another kind of runtime/compile time generic implementation later down the line if the other possible issues with those are solved.

Share:
liam avatar
liam
voted yes
1

It's about time :)

Share:
grzegorzdrozd avatar
grzegorzdrozd
voted yes
1

doc blocks are ugly, needs more lines of code. this rfc is the way to go.

Share:
kusowl avatar
kusowl
voted yes
1

This might be the most important PHP RFC of this decade.

Share:
ace-of-aces avatar
ace-of-aces
voted yes
1

Maybe the only missing feature.

Share:
roman-3 avatar
roman-3
voted yes
1
Share:
afraca avatar
afraca
voted yes

Check out another RFCs

Asymmetric Visibility v2

A new syntax for declaring the “set” operation visibility of an object property

23
21 yes
40 no
The Pipe Operator

The "pipe operator" |> allows you to chain multiple function calls in a more convenient way.

93
272 yes
131 no
Property Hooks

A new way of interacting with properties

70
142 yes
90 no
RSS Feed Contribute Watch on YouTube Our License
© 2026 RFC Vote. This project is open source. Contribute and collaborate with us!