Re: [PATCH] [RFC] Closures and lambda functions in PHP
| From: | troels knak-nielsen | Date: | Thu, 19 Jun 2008 08:52:50 +0000 |
| Subject: | Re: [PATCH] [RFC] Closures and lambda functions in PHP | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-38376@lists.php.net to get a copy of this message | ||
On Thu, Jun 19, 2008 at 8:44 AM, Andi Gutmans <andi@zend.com> wrote:
>> >> - In PHP 5, object storage is resources done right. I don't think
>> >> we should be using the resource infrastructure for this
>> >> implementation and would prefer to use the object one. It's better.
>> >> I suggest to take a look at it.
>>
>> Hmm, seems like a good idea. If nobody objects in the next few days,
>> I'll rewrite my patch to use objects instead of resources. What class
>> name do you suggest?
>
> Great. I think Closure is probably a good name.
> [Btw, if we want to get fancy we could even have a __toString() method on those which would
> print out information about the Closure. But this is not a must, just something which eventually
> could be nice for debugging purposes...]
>
Using objects, instead of resources is an excellent idea. Would it be
possible to introduce a general __invoke (Or whatever name is more
fitting) magic-method, so that whichever object implements that
method, is callable with call_user_func (and directly through
variable-function-syntax). Eg.:
class Foo {
function __invoke($thing) {
echo "Foo: " . $thing;
}
}
$foo = new Foo();
$foo("bar"); // > echoes "Foo: bar"
I'm not sure how this would play together with lexical scope?
--
troels