Re: [RFC] First-class callable syntax
| From: | Nikita Popov | Date: | Thu, 20 May 2021 17:05:14 +0000 |
| Subject: | Re: [RFC] First-class callable syntax | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-114539@lists.php.net to get a copy of this message | ||
On Thu, May 20, 2021 at 6:22 PM Luis Henrique <luis@softsatsistemas.com.br>
wrote:
> On 20/05/2021 12:55, Guilliam Xavier wrote:
> > On Thu, May 20, 2021 at 5:12 PM Nikita Popov <nikita.ppv@gmail.com>
> wrote:
> >
> >> On Thu, May 20, 2021 at 4:16 PM Ondřej Mirtes <ondrej@mirtes.cz> wrote:
> >>
> >>> Hi, I’m confused by the syntax, when I read it, I think to myself “I
> know
> >>> this, this is just a method call… oh wait, it’s actually a callable”.
> It
> >>> really makes my head hurt.
> >>>
> >>
> >> Yes, I can see how that could be confusing. The current syntax is
> chosen to
> >> be a subset of the partial function application proposal. However, I
> would
> >> also be happy with some other syntax that makes it clearer that this is
> >> acquiring a callable and not performing a call.
> >>
> >
> > Hi, several other syntaxes have been proposed to consideration in the PFA
> > thread, and I wouldn't want to start new bikeshedding here; is there a
> > place that would be more appropriate to gather the possibilities (like a
> > kind of updatable list)?
> >
> > Thanks,
> >
>
> I am much more into advanced features of PFA, but is this case why not
> just use the & operator for "function reference" like C/C++? It is well
> known and solves the ambiguity with method/function call.
>
> $fn = &$this->myFunc;
>
> $fn = &myFunc;
>
> $fn = &Foo::myFunc;
>
Unfortunately, this syntax is trivially ambiguous. "$fn = &$this->myFunc"
is currently already interpreted as a reference assignment of the property
$this->myFunc.
I have updated
https://wiki.php.net/rfc/first_class_callable_syntax#syntax_choice
to
discuss some of the obvious suggestions and why they don't work.
Regards,
Nikita