Re: [RFC] Syntax for variadic functions

From: Date: Thu, 29 Aug 2013 11:10:46 +0000
Subject: Re: [RFC] Syntax for variadic functions
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
2013/8/28 Nikita Popov <[email protected]>:
> Hi internals!
>
> I'd like to propose an RFC, which adds dedicated syntax for variadic
> functions:
>
>     https://wiki.php.net/rfc/variadics
>
> Basically this allows declaring variadics directly in the function
> signature, rather than fetching the arguments using func_get_args().
> Example:
>
>     public function query($query, ...$params) { /* ... */ }
>
> What are your thoughts on this?
>
> Thanks,
> Nikita

Using the current variadic functions makes it possible to use 0 or N
arguments, e.g.:

function sum() {
    return array_sum(func_get_args());
}

echo sum(10, 5); // echoes 15
echo sum(); // echoes 0

I see nowhere in the RFC whether:

function sum(...$params) { /* */ }

Requires at minimum one argument or none.

I have the _feeling_ that you imply it's minimum one which I would
consider a bit inconsistent with the current "implementation".

Can you please clarify this Nikita?

Thanks


Thread (24 messages)

« previous php.internals (#68678) next »