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] (Marcus Boerger) Sun, 11 Jan 2009 15:19:18 +0100
| Newsgroups | php.zend-engine.cvs |
|---|---|
| Message-ID | <[email protected]> |
Hello Dmitry,
no I mean what the general technology, referred to as prototyping
requires. What in general someone expects when binding a function
to an object. Whether that is what JS does I couldn't count less.
Though on the other hand it is the only prototype language that I
use. Oh and continuing that thought, once again doing something in
a way they know already is a pretty cool trick.
marcus
Sunday, January 11, 2009, 2:48:29 PM, you wrote:
> 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
>>
Best regards,
Marcus