1--TEST--
2GH-8932 (Provide a way to get the called-scope of closures)
3--FILE--
4<?php
5class A {
6    public static function __callStatic($name, $args) {
7        echo static::class.'::'.$name, "\n";
8    }
9
10    public function __call($name, $args) {
11        echo static::class.'->'.$name, "\n";
12    }
13
14    public static function b() {
15        echo static::class.'::b', "\n";
16    }
17
18
19    public function c() {
20        echo static::class.'->c', "\n";
21    }
22
23    public function makeClosure() {
24        return function () {
25            echo static::class.'::{closure}'."\n";
26        };
27    }
28}
29
30class B extends A {}
31
32$c = ['B', 'b'];
33$d = \Closure::fromCallable($c);
34$r = new \ReflectionFunction($d);
35var_dump($r->getClosureCalledClass());
36$d();
37
38$c = [new B(), 'c'];
39$d = \Closure::fromCallable($c);
40$r = new \ReflectionFunction($d);
41var_dump($r->getClosureCalledClass());
42$d();
43
44$c = ['B', 'd'];
45$d = \Closure::fromCallable($c);
46$r = new \ReflectionFunction($d);
47var_dump($r->getClosureCalledClass());
48$d();
49
50$c = [new B(), 'e'];
51$d = \Closure::fromCallable($c);
52$r = new \ReflectionFunction($d);
53var_dump($r->getClosureCalledClass());
54$d();
55
56$c = ['A', 'b'];
57$d = \Closure::fromCallable($c);
58$r = new \ReflectionFunction($d);
59var_dump($r->getClosureCalledClass());
60$d();
61
62$b = new B();
63$d = $b->makeClosure();
64$r = new \ReflectionFunction($d);
65var_dump($r->getClosureCalledClass());
66$d();
67
68$d = function () {
69    echo "{closure}\n";
70};
71$r = new \ReflectionFunction($d);
72var_dump($r->getClosureCalledClass());
73$d();
74
75?>
76--EXPECTF--
77object(ReflectionClass)#%d (1) {
78  ["name"]=>
79  string(1) "B"
80}
81B::b
82object(ReflectionClass)#%d (1) {
83  ["name"]=>
84  string(1) "B"
85}
86B->c
87object(ReflectionClass)#%d (1) {
88  ["name"]=>
89  string(1) "B"
90}
91B::d
92object(ReflectionClass)#%d (1) {
93  ["name"]=>
94  string(1) "B"
95}
96B->e
97object(ReflectionClass)#%d (1) {
98  ["name"]=>
99  string(1) "A"
100}
101A::b
102object(ReflectionClass)#%d (1) {
103  ["name"]=>
104  string(1) "B"
105}
106B::{closure}
107NULL
108{closure}
109