On 11-02-2020 17:48, Dan Ackroyd wrote: > 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.
Given the fact that $() would only accept functions and methods as argument, this idea could be taken one step further by writing: $(foo); $($obj->Fot); $(Zoq::Fot); Referring to a method like this is normally not possible because it is ambiguous. However, wrapped inside $(), which only accepts functions and methods, the ambiguity disappears. The $() syntax is nice and short. And something completely new. As new syntax can only be 'spent' once, more familiar alternatives should be explored as well. Thinking about the existing list() and array() syntax, another possibility could be: closure(foo); closure($obj->Fot); closure(Zoq::Fot); It is slightly longer but more familiar syntax. On 11-02-2020 19:46, Larry Garfield wrote: > > I would love a nicer way to reference function names; it's really ugly to do functional code in PHP otherwise, or even just dynamic function logic within a namespace. If I never have to write $fn = __NAMESPACE__ . '\a_func' again, it will be too soon. :-) Perhaps Larry can convince us all to go for something like $() by posting a fabulous functional programming example? Regards, Dik Takken -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php