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 11:09:14 +0300
| Newsgroups | php.zend-engine.cvs |
|---|---|
| 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
>
>