Re: [PHP-DEV] [Discussion] Revisiting typed closures

[email protected] (Seifeddine Gmati)
Newsgroups php.internals
Message-ID <CAFyg4Hgi1MHFMRjww-WX6FU-0hWCFGFsaq7JzDxbbGdxA4=U9g@mail.gmail.com>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.