Re: [RFC] Argument unpacking
| From: | Nikita Popov | Date: | Fri, 30 Aug 2013 17:06:40 +0000 |
| Subject: | Re: [RFC] Argument unpacking | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-68740@lists.php.net to get a copy of this message | ||
On Fri, Aug 30, 2013 at 6:57 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> And something like:
> test(1, 2, ...[3, 4], 5, 6, ...[7, 8])
>
> looks plain weird. What would be the use case for doing something like
> that?
No use case at all. This is a technical specification, so I write down what
is possible, not necessarily what you'd write in your code. Of course it
makes no sense to write something like ...[1, 2, 3], because you could just
as well write 1, 2, 3 directly. The point of that example is that it's
possible to mix it with normal arguments. The "practical" example for that
is the example in the introduction: $db->query($query, ...$params). Here a
"normal" argument is followed by an unpacked argument.
> This is just another way of doing call_user_func, I'm not sure we really
need it.
Assuming you mean call_user_func_array, yes. This is just syntax sugar for
call_user_func_array. Advantages of this syntax over cufa are outlined
here:
https://wiki.php.net/rfc/argument_unpacking#advantages_over_call_user_func_array
Thanks,
Nikita