Re: [RFC]
| From: | Rowan Tommins | Date: | Fri, 14 Feb 2020 08:23:06 +0000 |
| Subject: | Re: [RFC] | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-108560@lists.php.net to get a copy of this message | ||
On 14 February 2020 00:39:15 GMT+00:00, Mike Schinkel <mike@newclarity.net> wrote:
>> On Feb 13, 2020, at 7:24 PM, Rowan Tommins <rowan.collins@gmail.com>
>wrote:
>>
>> An idea I had earlier which might solve some of them is if what was
>returned was not a normal Closure instance, but a new class like
>FunctionReference. It could then "remember" the name of the function
>wrapped, and implement __toString, Serializable, etc. It could inherit
>from Closure, so instanceof checks would work, and bindTo would return
>a normal Closure. I'm sure there's downsides I haven't thought of yet,
>but I thought I'd throw the idea into the mix.
>
>I thought about that too, and mentioned it yesterday in a reply[1] to
>you on this list.
>
>Here is the link to the Gist with the hypothetical code using such a
>concept:
>
>-
>https://gist.github.com/mikeschinkel/78684d708358e1d101e319c7a2fdef9c
What I had in mind was a combination of that and the existing Closure class, so:
$ref = foo::fn;
$ref(); // run the function
$ref->name; // access extra metadata
$ref->bindTo($whatever); // get a new Closure with a bound context
That would also combine well with one of the proposed bracket style syntaxes that let you specify
methods more naturally:
{foo}->name; // qualified name of local function
{Foo::bar}; // closure for a static method
{$this->baz}->bindTo($that); // closure for a method of current class rebound to a different
object
Regards,
--
Rowan Tommins
[IMSoP]