summaryrefslogtreecommitdiff
path: root/Zend/tests/closure_036.phpt
blob: 0f8ccb1eda7c0ba58a6c6c16f83b07fe7e900f59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--TEST--
Closure 036: Rebinding closures
--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($b, $ca);

var_dump($ca());
var_dump($cb());
var_dump($cb2());

?>
--EXPECTF--
int(1)
int(11)
int(12)