xref: /PHP-8.1/Zend/tests/closure_058.phpt (revision 7aacc705)
1--TEST--
2Closure 058: Closure scope and object
3--FILE--
4<?php
5class A {
6    static function foo() {
7        return function () {var_dump(get_class(),get_called_class());};
8    }
9    function bar() {
10        return function () {var_dump(get_class(),get_called_class(),$this);};
11    }
12}
13$z = "call_user_func";
14
15$a = A::foo();
16$a();
17$a->__invoke();
18$c = array($a,"__invoke");
19$c();
20call_user_func(array($a,"__invoke"));
21$z(array($a,"__invoke"));
22
23echo "\n";
24
25$x = new A();
26$b = $x->bar();
27$b();
28$b->__invoke();
29$c = array($b,"__invoke");
30$c();
31call_user_func(array($b,"__invoke"));
32$z(array($b,"__invoke"));
33?>
34--EXPECT--
35string(1) "A"
36string(1) "A"
37string(1) "A"
38string(1) "A"
39string(1) "A"
40string(1) "A"
41string(1) "A"
42string(1) "A"
43string(1) "A"
44string(1) "A"
45
46string(1) "A"
47string(1) "A"
48object(A)#2 (0) {
49}
50string(1) "A"
51string(1) "A"
52object(A)#2 (0) {
53}
54string(1) "A"
55string(1) "A"
56object(A)#2 (0) {
57}
58string(1) "A"
59string(1) "A"
60object(A)#2 (0) {
61}
62string(1) "A"
63string(1) "A"
64object(A)#2 (0) {
65}
66