Re: [Discussion] Revisiting typed closures

From: Date: Wed, 01 Jul 2026 20:42:15 +0000
Subject: Re: [Discussion] Revisiting typed closures
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-131680@lists.php.net to get a copy of this message
Hi Osama, > The syntax collides at the lexer. Closure(int): array > can't be tokenized cleanly, because (int) is a cast token (same > for (string), (array), and so on). > It's been that way for years, and the one attempt to fix it (PR > https://github.com/php/php-src/pull/1667) was rejected as a > token-stream BC break. > So the natural spelling is, unfortunately, the engine-hostile one. This is fixable, it's not a real limitation. > There's a single Closure class (Ilija's point here: > https://externals.io/message/120083#120099), so > Closure(int, string): array isn't a subtype you can > instanceof... > it has to be checked another way at the boundary, which is where the usual per-boundary > runtime-cost concern comes in. I agree on this, I think the fn keyword should be used here.

« previous php.internals (#131680) next »