Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69300 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32689 invoked from network); 23 Sep 2013 20:35:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Sep 2013 20:35:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.197 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.197 imap3-2.ox.registrar-servers.com Received: from [192.64.116.197] ([192.64.116.197:51840] helo=imap3-2.ox.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/45-07641-506A0425 for ; Mon, 23 Sep 2013 16:35:19 -0400 Received: from localhost (localhost [127.0.0.1]) by oxmail.registrar-servers.com (Postfix) with ESMTP id 64D9F2A006F for ; Mon, 23 Sep 2013 16:35:15 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap3.ox.registrar-servers.com Received: from oxmail.registrar-servers.com ([127.0.0.1]) by localhost (imap3.ox.registrar-servers.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id xTI2h55TJx4z for ; Mon, 23 Sep 2013 16:35:15 -0400 (EDT) Received: from [192.168.0.200] (unknown [94.10.74.149]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 02DFD2A0053 for ; Mon, 23 Sep 2013 16:35:14 -0400 (EDT) Message-ID: <5240A5E2.90507@ajf.me> Date: Mon, 23 Sep 2013 21:34:42 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: PHP internals References: <52409A4D.3070404@ajf.me> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Argument unpacking - Multiple unpacks and trailing arguments From: ajf@ajf.me (Andrea Faulds) On 23/09/2013 21:19, Nikita Popov wrote: > That's a general issue that's not really related to multiple unpacks. It > could just as well happen without any unpacks at all ( f(a => 'a', a => > 'b') ) or when unpacking an iterator (which is allowed to have duplicate > keys). Fair enough. However, I'm a little concerned about the other named parameters issue here. f(1, ...$args1, 2, ...$args2) would be quite straightforward with numerical arguments, but with multiple unpacks which can also unpack named parameters, I am worried things could get quite confusing. Then again, it would be perfectly possible to write awful code with array_merge etc. anyway, so I can't really object to it. > > The variadics RFC does not allow defining such functions, correct. But > it's a fact that our standard library already makes use of this pattern > (variadic arguments first and a fixed one at the end), so it seems > somewhat reasonable to support them too. > > Why would it make the code clearer? Using the array_uintersect example: > > // unpack with trailing arg > array_uintersect(...$arrays, $compare); > // array_merge > array_uintersect(...array_merge($arrays, array($compare))); > > Maybe I'm alone here, but I find the first line clearer than the second. > Actually, I'm changing my mind here. I can see the utility here dealing with existing functions. The inconsistency with the definition is still a bit irritating, since you can call such functions easily but the definitions would be as easy since you'd have to chop up the ...$args in the definition, but all may be sacrificed in the name of backwards-compatibility. :P -- Andrea Faulds http://ajf.me/