Hi Nicolas,

wt., 25 kwi 2023, 19:00 użytkownik Nicolas Grekas <
nicolas.grekas+...@gmail.com> napisał:

> Hi all,
>
>
> https://wiki.php.net/rfc/allow_casting_closures_into_single-method_interface_implementations
> >
> >
> https://wiki.php.net/rfc/allow-closures-to-declare-interfaces-they-implement
> > https://wiki.php.net/rfc/structural-typing-for-closures
>
>
> Thanks Larry for the nice introduction to those ideas.
>
> Personally, I feel like going with adding Closure::castTo() might provide
> the most immediate benefit. I expanded the rationale on the corresponding
> RFC and added more examples. I'd appreciate it if all of you reading could
> have another look to see if that helps to better understand the proposal.
>
> strtr(...)->castTo(TranslatableInterface::class) is one example of RFC #1
> function ($message, $parameters) implements TranslatableInterface is RFC #2
>
> Both RFCs nicely combine together to cover many cases of typed callabled.
>
> Then RFC#3 is a bit more adventurous (according to our understanding) but
> still desirable as it's essentially about allowing the engine to
> tentatively call castTo() from RFC#1 when a closure is passed as argument
> while an interface is expected.
>

Personally I don't like this way of shaping callable types. Given examples
are really confusing me. Call of a castTo() with argument representing an
interface with a method is confusing as the method magically appears on a
closure without explicit binding to it! What if an interface has more than
one method? What if I wanna choose which one?

For me personally this goes into wrong direction.

Cheers,
Michał Marcin Brzuchalski

>

Reply via email to