1--TEST--
2Reflection on closures
3--FILE--
4<?php
5
6$closure = function($a, $b = 0) { };
7
8$ro = new ReflectionObject($closure);
9$rm = $ro->getMethod('__invoke');
10var_dump($rm->getNumberOfParameters());
11var_dump($rm->getNumberOfRequiredParameters());
12$rms = $ro->getMethods();
13foreach($rms as $rm) {
14    if ($rm->getName() == '__invoke') {
15        var_dump($rm->getNumberOfParameters());
16        var_dump($rm->getNumberOfRequiredParameters());
17    }
18}
19
20echo "---\n";
21
22$rm = new ReflectionMethod($closure, '__invoke');
23var_dump($rm->getName());
24var_dump($rm->getNumberOfParameters());
25var_dump($rm->getNumberOfRequiredParameters());
26
27echo "---\n";
28
29$rp = new ReflectionParameter(array($closure, '__invoke'), 0);
30var_dump($rp->isOptional());
31$rp = new ReflectionParameter(array($closure, '__invoke'), 1);
32var_dump($rp->isOptional());
33$rp = new ReflectionParameter(array($closure, '__invoke'), 'a');
34var_dump($rp->isOptional());
35$rp = new ReflectionParameter(array($closure, '__invoke'), 'b');
36var_dump($rp->isOptional());
37
38echo "---\n";
39
40$rp = new ReflectionParameter($closure, 0);
41var_dump($rp->isOptional());
42$rp = new ReflectionParameter($closure, 1);
43var_dump($rp->isOptional());
44$rp = new ReflectionParameter($closure, 'a');
45var_dump($rp->isOptional());
46$rp = new ReflectionParameter($closure, 'b');
47var_dump($rp->isOptional());
48
49?>
50--EXPECT--
51int(2)
52int(1)
53int(2)
54int(1)
55---
56string(8) "__invoke"
57int(2)
58int(1)
59---
60bool(false)
61bool(true)
62bool(false)
63bool(true)
64---
65bool(false)
66bool(true)
67bool(false)
68bool(true)
69