Re: [PHP-DEV] [RFC]

This is only part of a thread. view whole thread
  108492
February 11, 2020 17:41 manuelcanga@gmail.com (Manuel Canga)
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
Other option: Closure::fromCallable('foo'); Closure::fromCallable([$obj, 'Fot']); Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq', 'Fot']); to <$foo, Fot> E.g: array_map(, $array); array_map(, $array); Do you like ?
  108495
February 11, 2020 19:01 michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=)
wt., 11 lut 2020, 18:42 użytkownik Manuel Canga <manuelcanga@gmail.com>
napisał:

> 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 > > Other option: > > Closure::fromCallable('foo'); > Closure::fromCallable([$obj, 'Fot']); > Closure::fromCallable('Zoq::Fot'); or Closure::fromCallable(['Zoq', > 'Fot']); > > to > > > <$foo, Fot> > > > > E.g: > > array_map(, $array); > array_map(, $array); > > Do you like ? >
That reminds me an old draft RFC https://wiki.php.net/rfc/short-closures where I thought curly braces can be used to create closure from syntax nearly the same as invoking but without parentheses. That way we can provide clear intent - I mean if whatever is around: curly braces or $ with parentheses IMHO it should be consistent with call like format. For example: $(strlen) or {strlen} for Closure::fromCallable('foo') $($foo->Fot) or {$foo->Fot} for Closure::fromCallable([$obj, 'Fot']) $(Zoq::Fot) or {Zoq::Fot} for Closure::fromCallable('Zoq::Fot') Etc. The same inside like a call but wrapped in something and with no parentheses part. Cheers, -- Michał Brzuchalski
>
  108500
February 11, 2020 20:14 d.h.j.takken@freedom.nl (Dik Takken)
On 11-02-2020 20:01, Michał Brzuchalski wrote:
> wt., 11 lut 2020, 18:42 użytkownik Manuel Canga <manuelcanga@gmail.com> > napisał: > > That reminds me an old draft RFC https://wiki.php.net/rfc/short-closures > where I thought curly braces can be used to create closure from syntax > nearly the same as invoking but without parentheses.
My message mentioning just about the same idea crossed yours. Thanks for pointing at this RFC, I think it just caught our attention again. :) I quickly scanned the list to see if your RFC was discussed and all I could find was threads about a different RFC with almost identical name (https://wiki.php.net/rfc/short_closures). Has it not been discussed before? Regards, Dik Takken
  108501
February 11, 2020 21:06 michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=)
wt., 11 lut 2020, 21:14 użytkownik Dik Takken takken@freedom.nl>
napisał:

> On 11-02-2020 20:01, Michał Brzuchalski wrote: > > wt., 11 lut 2020, 18:42 użytkownik Manuel Canga <manuelcanga@gmail..com> > > napisał: > > > > That reminds me an old draft RFC https://wiki.php.net/rfc/short-closures > > where I thought curly braces can be used to create closure from syntax > > nearly the same as invoking but without parentheses. > > My message mentioning just about the same idea crossed yours. Thanks for > pointing at this RFC, I think it just caught our attention again. :) > > I quickly scanned the list to see if your RFC was discussed and all I > could find was threads about a different RFC with almost identical name > (https://wiki.php.net/rfc/short_closures). Has it not been discussed > before? >
No, it hasn't been discussed. It stopped at being a draft. BR, -- Michał Brzuchalski
>