Re: [RFC] Syntax for variadic functions

From: Date: Wed, 28 Aug 2013 22:09:19 +0000
Subject: Re: [RFC] Syntax for variadic functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi!

I like the idea, the concept of capturing "rest of args" is pretty
common. But couldn't we in addition have func_get_args() be able to
receive an int argument that would produce "the rest" in an easier way
for those that prefer func_ger_args()?

I wonder if this makes harder to implement named argument in the future
- which I think we still need to be looking at - but so far doesn't look
like it presents any additional problem compared to func_get_args().

For prototype checks, this:

    public function query($query, ...$params);
    public function query($query, $param = null, ...$params);

Should be compatible. Same with:

    public function query($query, ...$params);
    public function query($query);

functions should be able to ignore some arguments, especially ones that
are optional anyway. I also think this:

public function query($query, ...$params)
public function query(...$params)

should be legal too.

I think it should also be explicitly specified what $params is if there
is no arguments - null? false? array()? I'd probably prefer array as it
makes it easy to do something like:

public __construct(...$params) {
  foreach($params as $k => $v) { $this->$k = $v; }
}

but in any way it should be specified.

I didn't look at the implementation yet, so I'll add comments on that
later.
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227


Thread (24 messages)

« previous php.internals (#68656) next »