Re: cvs: ZendEngine2 / zend_closures.c zend_closures.h zend_object_handlers.c /tests closure_033.phpt closure_034.phpt

Dmitry Stogov <[email protected]>
Newsgroups gmane.comp.php.cvs.zend
Message-ID <[email protected]>
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
>   
> 

-- 
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.