xref: /PHP-8.0/Zend/tests/closure_036.phpt (revision f8d79582)
1--TEST--
2Closure 036: Rebinding closures, keep calling scope
3--FILE--
4<?php
5
6class A {
7    private $x;
8
9    public function __construct($v) {
10        $this->x = $v;
11    }
12
13    public function getIncrementor() {
14        return function() { return ++$this->x; };
15    }
16}
17
18$a = new A(0);
19$b = new A(10);
20
21$ca = $a->getIncrementor();
22$cb = $ca->bindTo($b);
23$cb2 = Closure::bind($ca, $b);
24
25var_dump($ca());
26var_dump($cb());
27var_dump($cb2());
28
29?>
30--EXPECT--
31int(1)
32int(11)
33int(12)
34