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/
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.
NO!
One could add a getParmNo() or such if really needed while I think
reflection is better (as it also gives parameter information about
required/optional and type "hints")
Countable implies ArrayAccess or such.
johannes
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.
NO!
One could add a getParmNo() or such if really needed while I think
reflection is better (as it also gives parameter information about
required/optional and type "hints")Countable implies ArrayAccess or such.
If it is the semantics you ascribe to \Countable, then ok, there is no
problem :-).
--
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/
Hello,
2011/8/8 Johannes Schlüter johannes@schlueters.de:
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.NO!
One could add a getParmNo() or such if really needed while I think
reflection is better (as it also gives parameter information about
required/optional and type "hints")Countable implies ArrayAccess or such.
I don't believe Countable implies ArrayAccess, but I do think that
Countable should only be implemented in cases where it is obvious what
it will return, for example collections.
In this case, count(Closure) is really not that explicit, I'd rather
have an explicit method.
Best,
johannes
--
--
Etienne Kneuss
http://www.colder.ch
I don't believe Countable implies ArrayAccess, but I do think that
Countable should only be implemented in cases where it is obvious what
it will return, for example collections.In this case, count(Closure) is really not that explicit, I'd rather
have an explicit method.
ACK
--
Sebastian Bergmann Co-Founder and Principal Consultant
http://sebastian-bergmann.de/ http://thePHP.cc/
I think it's just a bad habit inherited from Javascript, where you can
do like this:
var a = function(a, b) { };
alert(a.length); // shows 2
I don't think that PHP needs it, explicit method is way better.
2011/8/8 Sebastian Bergmann sebastian@php.net:
I don't believe Countable implies ArrayAccess, but I do think that
Countable should only be implemented in cases where it is obvious what
it will return, for example collections.In this case, count(Closure) is really not that explicit, I'd rather
have an explicit method.ACK
--
Sebastian Bergmann Co-Founder and Principal Consultant
http://sebastian-bergmann.de/ http://thePHP.cc/--
--
Regards,
Shein Alexey
I think it's just a bad habit inherited from Javascript, where you can
do like this:
var a = function(a, b) { };
alert(a.length); // shows 2I don't think that PHP needs it, explicit method is way better.
I am agreeing with the fact that we don't need any more magic in PHP
and explicit methods go much further than any magic you can add to a
language.
2011/8/8 Sebastian Bergmann sebastian@php.net:
I don't believe Countable implies ArrayAccess, but I do think that
Countable should only be implemented in cases where it is obvious what
it will return, for example collections.In this case, count(Closure) is really not that explicit, I'd rather
have an explicit method.ACK
--
Sebastian Bergmann Co-Founder and Principal Consultant
http://sebastian-bergmann.de/ http://thePHP.cc/--
--
Regards,
Shein Alexey
I think it's just a bad habit inherited from Javascript, where you can
do like this:
var a = function(a, b) { };
alert(a.length); // shows 2I don't think that PHP needs it, explicit method is way better.
I am agreeing with the fact that we don't need any more magic in PHP
and explicit methods go much further than any magic you can add to a
language.
I'm also agreeing :-). It was just a proposition.
Cheers.
--
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/