Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_closures.c zend_closures.h zend_object_handlers.c /tests closure_033.phpt closure_034.phpt
[email protected] (Dmitry Stogov) Sun, 11 Jan 2009 16:48:29 +0300
| Newsgroups | php.zend-engine.cvs |
|---|---|
| Message-ID | <[email protected]> |
Do you mean JavaScript like tricks which allow to create new methods by
assigning closures to object properties?
As I remember, it was decided not to support it.
Thanks. Dmitry.
Marcus Boerger wrote:
> Hello Dmitry,
>
> it's what prototyping requires. I just made this behave as expected.
>
> marcus
>
> Sunday, January 11, 2009, 9:09:14 AM, you wrote:
>
>> Hi Marcus,
>
>> I'm wondered where this behavior comes from (It was never proposed or
>> may be I missed it).
>
>> Now, the simple assignment of closure to property and back changes its
>> internal $this pointer.
>
>> As result the following example is broken.
>
>> <?php
>> class A {
>> private $a = 0;
>> public $bar;
>> function foo() {
>> return function() {
>> return $this->a++;
>> };
>> }
>> }
>> class B {
>> public $bar;
>> function foo($a) {
>> return $a->foo();
>> }
>> }
>> $a = new A;
>> $b = new B;
>> $f1 = $a->foo();
>> $f2 = $b->foo($a);
>> var_dump($f1());
>> var_dump($f1());
>> var_dump($f2());
>> var_dump($f2());
>> var_dump($f1());
>> $a->bar = $f1;
>> $b->bar = $f2;
>> $f1 = $a->bar;
>> $f2 = $b->bar; // REASON OF THE BUG
>> var_dump($f1());
>> var_dump($f1());
>> var_dump($f2()); // BUG
>> var_dump($f2());
>> var_dump($f1());
> ?>>
>
>> Thanks. Dmitry.
>
>
>> Marcus Boerger wrote:
>>> helly Sat Jan 3 17:46:25 2009 UTC
>>>
>>> Added files:
>>> /ZendEngine2/tests closure_033.phpt closure_034.phpt
>>>
>>> Modified files:
>>> /ZendEngine2 zend_closures.c zend_closures.h zend_object_handlers.c
>>> Log:
>>> - Rebind closure when binding to property
>>>
>>>
>
>
>
>
> Best regards,
> Marcus
>