summaryrefslogtreecommitdiff
path: root/Zend/tests/closure_062.phpt
blob: b8c0a981be5276f4806916611df69faa0d6a7187 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--TEST--
Closure $this unbinding deprecation
--FILE--
<?php

class Test {
    public function method() {
        echo "instance scoped, non-static, \$this used\n";
        $fn = function() {
            var_dump($this);
        };
        $fn->bindTo(null);
        echo "instance scoped, static, \$this used\n";
        $fn = static function() {
            var_dump($this);
        };
        $fn->bindTo(null);
        echo "instance scoped, non-static, \$this not used\n";
        $fn = function() {
            var_dump($notThis);
        };
        $fn->bindTo(null);
    }

    public static function staticMethod() {
        echo "static scoped, non-static, \$this used\n";
        $fn = function() {
            var_dump($this);
        };
        $fn->bindTo(null);
        echo "static scoped, static, \$this used\n";
        $fn = static function() {
            var_dump($this);
        };
        $fn->bindTo(null);
        echo "static scoped, static, \$this not used\n";
        $fn = function() {
            var_dump($notThis);
        };
        $fn->bindTo(null);
    }
}

(new Test)->method();
Test::staticMethod();

?>
--EXPECTF--
instance scoped, non-static, $this used

Warning: Cannot unbind $this of closure using $this in %s on line %d
instance scoped, static, $this used
instance scoped, non-static, $this not used
static scoped, non-static, $this used
static scoped, static, $this used
static scoped, static, $this not used