> -----Original Message----- > From: Lars Strojny [mailto:l...@strojny.net] > Sent: Monday, September 23, 2013 9:37 PM > To: Nikita Popov > Cc: PHP internals > Subject: Re: [PHP-DEV] Argument unpacking - Multiple unpacks and trailing > arguments > > Hi Nikita, > > Am 23.09.2013 um 21:33 schrieb Nikita Popov <nikita....@gmail.com>: > [...] > > An example of trailing arguments are array intersections and diffs > > using a custom compare function: > > > > array_uintersect(...$arrays, $compare); > > array_udiff(...$arrays, $compare); > > // also array_intersect_uassoc and all those other variations on > > the topic > > > > Some people expressed concern about allow both usages (multiple > > unpacks / trailing args). I have a bit of a hard time understanding > > this (as there clearly are practical applications for both), so I'd > > appreciate some more opinions on the topic. > > Although it might allow users to shoot into their foot, I prefer having it > instead of introducing a limitation that is not technically necessary. So +1 > > cu, > Lars [Robert Stoll] Personally I would allow multiple unpacking but not allow unpacking for non-variadic parameters thus:
function foo(...$arr){} foo(...$arr, ...$arr2); //is fine function foo(...$arr){} foo(1, 2, ...$arr, ...$arr2); //is fine function foo($foo, $bar, ...$arr){} foo(1,2,...$arr, ...$arr2); //is fine as well function foo($foo, $bar, ...$arr){} foo(1, ...$arr, ...$arr2, 2); //shouldn't be allowed IMO - ...$arr is not passed to a variadic parameter And I would definitely not allow things like the following (but I think you removed it already from the RFC) function foo($bar, $baz, $buz, $boz, $booz, $booze){} foo(..$arr, 2, ..$arr2); I think the readability is harmed when the user is not able to tell directly which arguments are passed to which parameters. For instance: function foo($foo, $bar){} function bar($foo, $bar, ...$arg){} function doIt(Iterator $iterator){ foo(...$iterator); bar(...$iterator); } Depending on the implementation of $iterator the value passed to the parameters $foo and $bar will be different (regardless of the ...$arg in function bar) and you will have a hard time to understand the code quickly. As far as I understood PHP should be easy learnable, I think doing unpacking arguments in a wrong way can hinder this and the language should restrict it. IMO the implementation of array_uintersect should follow the same rule as variadics in a later version (6.x or whatever) Cheers, robert -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php