Re: [Discussion] Revisiting typed closures

From: Date: Wed, 01 Jul 2026 19:02:27 +0000
Subject: Re: [Discussion] Revisiting typed closures
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-131669@lists.php.net to get a copy of this message
> I would rather wait for generics and possibly make Closure a generic type.. > > — Rob Hi Rob, I don't think generics help here. PHP doesn't have generics at all yet, and realistically they're at least a couple of years away. But even once they land, they wouldn't solve this. Making Closure generic (e.g., say Closure<Input, Output> ) would require Input to be variadic to stand in for a closure's parameter list, and variadic generics are a different beast entirely. They've never appeared in any proposal, they don't really make sense for a number of reasons, and if they were ever added at all, it would be years after generics themselves. So "wait for generics" here effectively means waiting indefinitely. And arity aside, a generic Closure<...> still couldn't express which arguments are required versus optional, nor type a closure that is itself generic. A dedicated syntax like fn<T>(T, string=): T handles all of it cleanly: - The generic parameter ( <T> ) - Te required and optional arguments ( = marker ) - The return type ( following : ) Cheers, Seifeddine

« previous php.internals (#131669) next »