func_num_args() must be called inside the Closure to know the number of arguments that it received. If you are calling outside, it returns the number of arguments of your testClosure function. There is no other way than Reflection to do this.
And, I think func_num_args() does not receive any parameter. On Tue, Dec 20, 2011 at 9:43 PM, Mark <mark...@gmail.com> wrote: > Hi, > > Why is func_num_args not working on closures? > Example code (tested on PHP 5.3.8): > > <?php > > class Test > { > public function testClosure($oClosure) > { > echo '<pre>'; > print_r(func_num_args($oClosure)); > echo '<pre>'; > } > } > > $c = new Test(); > $c->testClosure(function($arg1, $arg2){ > }); > > That returns 1 (the num of args in which function the closure is > (testClosure), but not the number of args from the closure itself. > Now Reflection can be used to get the number of args but that is overkill! > Also when you would do print_r(func_get_args($oClosure)); you do get > "something" back including the arguments but no way (that i know) to use > them! > > Just something that i wonder... > I would have expected num args to return the args of the function you > provide it.. > > Kind regards, > Mark -- Atenciosamente, Rafael Kassner -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php