Re: [RFC]
| From: | Manuel Canga | Date: | Tue, 11 Feb 2020 17:21:01 +0000 |
| Subject: | Re: [RFC] | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108490@lists.php.net to get a copy of this message | ||
On Tue, 11 Feb 2020 at 17:49, Dan Ackroyd <Danack@basereality.com> wrote:
>
> Nicolas Grekas wrote:
> > I wish this would return a Closure instead, making $foo::function the
> > equivalent of Closure::fromCallable($foo).
>
> I didn't include the following in that RFC, because I thought it would
> be too controversial, but I think it's worth considering a new syntax
> for this.
>
> Given the code:
>
> function foo();
> class Zoq {
> public function Fot() {}
> public static function Pik() {}
> }
> $obj = new Zoq();
>
>
> Then these:
>
> $(foo);
> $($obj, Fot);
> $(Zoq, Fot);
>
> Would be equivalent to:
>
> Closure::fromCallable('foo');
> Closure::fromCallable([$obj, 'Fot']);
> Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq',
> 'Fot']);
>
> Or similar.
>
> The justification for having a dedicated syntax is that I think
> readability is quite important in code, and it's reasonably common for
> me to have quite long lists of 'callables'.
>
> [Bar::class, foo1::function],
> [Bar::class, foo2::function],
> [Bar::class, foo3::function],
> [Bar::class, foo4::function]
>
> vs
>
> $(Bar, foo1),
> $(Bar, foo2),
> $(Bar, foo3),
> $(Bar, foo4)
>
> The latter is far easier to read for me.
>
> Nikita Popov wrote:
> > This would circumvent all the issues outlined in
> > https://wiki.php.net/rfc/consistent_callables.
>
> Probably there would still be some issues with some of the weird stuff
> happening internally in SPL related code where the deep horrors
> rest...but we can leave them alone...and they might not wake.
>
> cheers
> Dan
> Ack
Hi, Dan,
I like it, although syntax reminds me to JQuery syntax.
Thanks