Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69301 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39988 invoked from network); 23 Sep 2013 21:18:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Sep 2013 21:18:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=rstoll@tutteli.ch; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rstoll@tutteli.ch; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: rstoll@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:50632] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/90-37096-730B0425 for ; Mon, 23 Sep 2013 17:18:47 -0400 Received: (qmail 8305 invoked from network); 23 Sep 2013 23:18:43 +0200 Received: from heim-032-99.raab-heim.uni-linz.ac.at (HELO RoLaptop) (193.171.32.99) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 23 Sep 2013 23:18:43 +0200 To: "'Lars Strojny'" , "'Nikita Popov'" Cc: "'PHP internals'" References: <69BCC163-7988-4EBB-A817-5F5007EC924C@strojny.net> In-Reply-To: <69BCC163-7988-4EBB-A817-5F5007EC924C@strojny.net> Date: Mon, 23 Sep 2013 23:18:39 +0200 Message-ID: <004a01ceb8a2$7a586830$6f093890$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJ8bBjn5Gb3vZgYWihCGjPQ0G6pbQFa5RpnmG2VC2A= Content-Language: de-ch Subject: RE: [PHP-DEV] Argument unpacking - Multiple unpacks and trailing arguments From: rstoll@tutteli.ch ("Robert Stoll") > -----Original Message----- > From: Lars Strojny [mailto:lars@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 : > [...] > > 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