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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
<?php
function bar($param1)
{
return $param1;
}
$closure = function($param1) {
return $param1;
};
function test($fn)
{
static $count = 0;
$input = "foo".$count;
$count++;
$output = $fn($input);
return $input === $output;
}
class Foo
{
public static function publicStaticFunction($param1)
{
return $param1;
}
private static function privateStaticFunction($param1)
{
return $param1;
}
protected static function protectedStaticFunction($param1)
{
return $param1;
}
private function privateInstanceFunc($param1)
{
return $param1;
}
protected function protectedInstanceFunc($param1)
{
return $param1;
}
public function publicInstanceFunc($param1)
{
return $param1;
}
public function closePrivateValid()
{
return Closure::fromCallable([$this, 'privateInstanceFunc']);
}
public function closePrivateStatic()
{
return Closure::fromCallable([__CLASS__, 'privateStaticFunction']);
}
public function bar($param1)
{
echo "this is bar\n";
}
public function getCallable()
{
return Closure::fromCallable([$this, 'publicInstanceFunc']);
}
public function getSelfPublicInstance()
{
return Closure::fromCallable([$this, 'publicInstanceFunc']);
}
public function getSelfColonPublicInstanceMethod()
{
return Closure::fromCallable('self::publicInstanceFunc');
}
}
class SubFoo extends Foo {
public function closePrivateStaticInvalid()
{
return Closure::fromCallable([__CLASS__, 'privateStaticFunction']);
}
public function closePrivateInvalid()
{
return Closure::fromCallable([$this, 'privateInstanceFunc']);
}
public function closeProtectedStaticMethod()
{
return Closure::fromCallable([__CLASS__, 'protectedStaticFunction']);
}
public function closeProtectedValid()
{
return Closure::fromCallable([$this, 'protectedInstanceFunc']);
}
public function getParentPublicInstanceMethod()
{
return Closure::fromCallable('parent::publicInstanceFunc');
}
public function getSelfColonParentPublicInstanceMethod()
{
return Closure::fromCallable('self::publicInstanceFunc');
}
public function getSelfColonParentProtectedInstanceMethod()
{
return Closure::fromCallable('self::protectedInstanceFunc');
}
public function getSelfColonParentPrivateInstanceMethod()
{
return Closure::fromCallable('self::privateInstanceFunc');
}
}
class MagicCall
{
public function __call($name, $arguments)
{
$info = ['__call'];
$info[] = $name;
$info = array_merge($info, $arguments);
return implode(',', $info);
}
public static function __callStatic($name, $arguments)
{
$info = ['__callStatic'];
$info[] = $name;
$info = array_merge($info, $arguments);
return implode(',', $info);
}
}
class PublicInvokable
{
public function __invoke($param1)
{
return $param1;
}
}
function functionAccessProtected()
{
$foo = new Foo;
return Closure::fromCallable([$foo, 'protectedStaticFunction']);
}
function functionAccessPrivate()
{
$foo = new Foo;
return Closure::fromCallable([$foo, 'privateStaticFunction']);
}
function functionAccessMethodDoesntExist()
{
$foo = new Foo;
return Closure::fromCallable([$foo, 'thisDoesNotExist']);
}
?>
|