diff options
Diffstat (limited to 'Zend/tests/closure_036.phpt')
-rw-r--r-- | Zend/tests/closure_036.phpt | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Zend/tests/closure_036.phpt b/Zend/tests/closure_036.phpt new file mode 100644 index 0000000..77d7ce6 --- /dev/null +++ b/Zend/tests/closure_036.phpt @@ -0,0 +1,33 @@ +--TEST-- +Closure 036: Rebinding closures, keep calling scope +--FILE-- +<?php + +class A { + private $x; + + public function __construct($v) { + $this->x = $v; + } + + public function getIncrementor() { + return function() { return ++$this->x; }; + } +} + +$a = new A(0); +$b = new A(10); + +$ca = $a->getIncrementor(); +$cb = $ca->bindTo($b); +$cb2 = Closure::bind($ca, $b); + +var_dump($ca()); +var_dump($cb()); +var_dump($cb2()); + +?> +--EXPECTF-- +int(1) +int(11) +int(12)
\ No newline at end of file |