Hi Internals,

I would like to suggest you a new feature (for PHP5.4 or maybe next). The idea is to implement the \Countable interface into closures to easily count the arguments number. I know that it is already possible with reflection [1] but it could be a comfortable trick I think.
Subsidiary questions: do we include optional arguments in our calculation?

Here is a trivial example:

   class Closure implements \Countable { … }
   $f = function ( $x, $y, $z ) { … };
   var_dump(count($f));
   // int(3)

Javascript already implements this [2]:

   var f = function ( x, y, z ) { … };
   console.log(f.length);


Thoughts?


Best regards.

[1] <http://php.net/reflectionfunctionabstract.getnumberofparameters>
[2] <https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/length>

--
Ivan Enderlin
Developer of Hoa
http://hoa.42/ or http://hoa-project.net/

Member of HTML and WebApps Working Group of W3C
http://w3.org/



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to