xref: /PHP-7.4/Zend/tests/closure_058.phpt (revision fc80305e)
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--EXPECT--
34string(1) "A"
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"
44
45string(1) "A"
46string(1) "A"
47object(A)#2 (0) {
48}
49string(1) "A"
50string(1) "A"
51object(A)#2 (0) {
52}
53string(1) "A"
54string(1) "A"
55object(A)#2 (0) {
56}
57string(1) "A"
58string(1) "A"
59object(A)#2 (0) {
60}
61string(1) "A"
62string(1) "A"
63object(A)#2 (0) {
64}
65