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
|
--TEST--
Reflection on closures
--FILE--
<?php
$closure = function($a, $b = 0) { };
$ro = new ReflectionObject($closure);
$rm = $ro->getMethod('__invoke');
var_dump($rm->getNumberOfParameters());
var_dump($rm->getNumberOfRequiredParameters());
$rms = $ro->getMethods();
foreach($rms as $rm) {
if ($rm->getName() == '__invoke') {
var_dump($rm->getNumberOfParameters());
var_dump($rm->getNumberOfRequiredParameters());
}
}
echo "---\n";
$rm = new ReflectionMethod($closure, '__invoke');
var_dump($rm->getName());
var_dump($rm->getNumberOfParameters());
var_dump($rm->getNumberOfRequiredParameters());
echo "---\n";
$rp = new ReflectionParameter(array($closure, '__invoke'), 0);
var_dump($rp->isOptional());
$rp = new ReflectionParameter(array($closure, '__invoke'), 1);
var_dump($rp->isOptional());
$rp = new ReflectionParameter(array($closure, '__invoke'), 'a');
var_dump($rp->isOptional());
$rp = new ReflectionParameter(array($closure, '__invoke'), 'b');
var_dump($rp->isOptional());
echo "---\n";
$rp = new ReflectionParameter($closure, 0);
var_dump($rp->isOptional());
$rp = new ReflectionParameter($closure, 1);
var_dump($rp->isOptional());
$rp = new ReflectionParameter($closure, 'a');
var_dump($rp->isOptional());
$rp = new ReflectionParameter($closure, 'b');
var_dump($rp->isOptional());
?>
===DONE===
--EXPECT--
int(2)
int(1)
int(2)
int(1)
---
string(8) "__invoke"
int(2)
int(1)
---
bool(false)
bool(true)
bool(false)
bool(true)
---
bool(false)
bool(true)
bool(false)
bool(true)
===DONE===
|