Re: RFC: alternative callback syntax
| From: | Adam Harvey | Date: | Thu, 20 Sep 2012 09:05:24 +0000 |
| Subject: | Re: RFC: alternative callback syntax | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-63187@lists.php.net to get a copy of this message | ||
On 20 September 2012 16:24, Ivan Enderlin @ Hoa
<ivan.enderlin@hoa-project.net> wrote:
>
>> On 9/19/12 2:01 PM, Andrew Faulds wrote:
>>> $cb = {mysql_real_escape_string};
>>> $cb = &{mysql_real_escape_string};
>
> These notations are just horrible.
Agreed. They're very line noisey and non-obvious.
> PHP has recently introduced ::class to resolve a classname (namespace Foo;
> A::class // Foo\A). The “::” was originally a resolution operator for calls,
> but now, it is also used for names (which sounds good for me). Here, you
> propose the new notation ::function, which can be understood as: “resolve
> this function or method as a callable”. We stay in a resolution context. It
> is consistent regarding to the evolution of this operator.
I like ::callable, personally, since it suggests the resulting type,
but ::function would also be OK by me.
> Another consistent notation is the cast: (callable) $obj->bar;.
I think the analogy with ::class is stronger than the analogy with
type casting (since it's not a variable or literal), although I'm not
really too fussed either way.
In terms of the feature itself (since I haven't weighed in yet), I
think it's a reasonable piece of syntactic sugar, although I'd
definitely want to see a patch before voting. :)
Adam