[PHP-DEV] [Discussion] Revisiting typed closures

[email protected] (Matheus Martins)
Newsgroups php.internals
Message-ID <CAAZKEqj0o_KLAk=eAwYFBJCWUz1aKuCV21EYOG_7w34KnJknSg@mail.gmail.com>
Hello internals,

I would like to revisit the idea of giving closures a typed call signature.

e.g. Closure(int, string): array -- enforced at the point a value crosses a
type boundary (an argument, a return, a property), the same places any other
type is checked.

Today a closure can only be typed as Closure or callable, neither of which
says anything about its parameters or return, even though that information is
right there.

I know this is not new ground: Callable Prototypes was declined in 2016, and
Garfield and Grekas shared two further RFCs in 2023 -- Structural Typing for
Closures, and Allow Closures to Declare Interfaces they Implement -- both still
in draft.

Before taking it further, I would like to know whether closure typing
is still considered worth pursuing -- or whether the topic is now regarded as
settled.

References:

- https://wiki.php.net/rfc/callable-types
- https://wiki.php.net/rfc/structural-typing-for-closures
- https://wiki.php.net/rfc/allow-closures-to-declare-interfaces-they-implement

Thanks.
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.