xref: /php-src/Zend/tests/closure_040.phpt (revision 8e0789a2)
1--TEST--
2Closure 040: Rebinding closures, bad arguments
3--FILE--
4<?php
5
6class A {
7    private $x;
8    private static $xs = 10;
9
10    public function __construct($v) {
11        $this->x = $v;
12    }
13
14    public function getIncrementor() {
15        return function() { return ++$this->x; };
16    }
17    public function getStaticIncrementor() {
18        return static function() { return ++static::$xs; };
19    }
20}
21
22$a = new A(20);
23
24$ca = $a->getIncrementor();
25$cas = $a->getStaticIncrementor();
26
27try {
28    $ca->bindTo($a, array());
29} catch (TypeError $e) {
30    echo $e->getMessage(), "\n";
31}
32
33$cas->bindTo($a, 'A');
34
35?>
36--EXPECTF--
37Closure::bindTo(): Argument #2 ($newScope) must be of type object|string|null, array given
38
39Warning: Cannot bind an instance to a static closure in %s on line %d
40