Add \Countable support to \Closure
| From: | Ivan Enderlin @ Hoa | Date: | Mon, 08 Aug 2011 07:16:19 +0000 |
| Subject: | Add \Countable support to \Closure | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-54453@lists.php.net to get a copy of this message | ||
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/