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===DONE=== 51--EXPECT-- 52int(2) 53int(1) 54int(2) 55int(1) 56--- 57string(8) "__invoke" 58int(2) 59int(1) 60--- 61bool(false) 62bool(true) 63bool(false) 64bool(true) 65--- 66bool(false) 67bool(true) 68bool(false) 69bool(true) 70===DONE=== 71