On 14 February 2020 00:39:15 GMT+00:00, Mike Schinkel <m...@newclarity.net> wrote: >> On Feb 13, 2020, at 7:24 PM, Rowan Tommins <rowan.coll...@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] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php