php-src/Zend/tests/closure_036.phpt

34 lines
448 B
Plaintext
Raw Normal View History

--TEST--
Closure 036: Rebinding closures, keep calling scope
--FILE--
<?php
class A {
private $x;
2018-09-17 01:16:42 +08:00
public function __construct($v) {
$this->x = $v;
}
2018-09-17 01:16:42 +08:00
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());
?>
--EXPECT--
int(1)
int(11)
int(12)