Re: 5.3.8, Why is func_num_args() not working on a Clusure?

From: Date: Tue, 20 Dec 2011 23:55:50 +0000
Subject: Re: 5.3.8, Why is func_num_args() not working on a Clusure?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-56971@lists.php.net to get a copy of this message
Hi, The function func_num_args() doesn't accept any parameters, so calling func_num_args($oClosure) is the same as calling simple func_num_args(). That's why it returns 1 instead of 2, which is I think the expected and correct behavior. Gergo Erdosi On Dec 21, 2011, at 24:43 , Mark 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

« previous php.internals (#56971) next »