Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13239 invoked from network); 23 Sep 2013 20:19:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Sep 2013 20:19:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.179 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.179 mail-ob0-f179.google.com Received: from [209.85.214.179] ([209.85.214.179:41672] helo=mail-ob0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/41-07641-042A0425 for ; Mon, 23 Sep 2013 16:19:12 -0400 Received: by mail-ob0-f179.google.com with SMTP id wn1so3899313obc.38 for ; Mon, 23 Sep 2013 13:19:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=jkWh+bgWTB99VkqyKaLWx4Kpkani17JwWqPnjL8uo/Q=; b=P24EUFDkxO32sH79bm4oiz111qJPBFkllkJJ2PFnf6KTnrAiyVbIoZMmYkzg++UgMH akD9R/LanqZrPHIpUE9qpPFA0qd8FvLJncln718Ar0vty2Y8mRVg+vaYnhG5KAFY5EJ1 RoqH7J+xQfWbB7vfHYnoP1MM4zyXzFbPBPvO1rUQ9iBhU3BcUMsrqO0Ei62iGbVkWWi4 ENOyux5JJTVPuOR8AJT/tEV58FnT9iZZXQ5aNmBnfzf6EsODRnuCJQurmH/muEKBK+b9 Jil6pmNHJwKwDqmxFmM1AXTWKx6fkxHjngO8y/U3CIdF7xHGqJSNd07kwuEV8IuNFN49 08tQ== MIME-Version: 1.0 X-Received: by 10.182.22.226 with SMTP id h2mr21602890obf.8.1379967549574; Mon, 23 Sep 2013 13:19:09 -0700 (PDT) Received: by 10.182.98.8 with HTTP; Mon, 23 Sep 2013 13:19:09 -0700 (PDT) In-Reply-To: <52409A4D.3070404@ajf.me> References: <52409A4D.3070404@ajf.me> Date: Mon, 23 Sep 2013 22:19:09 +0200 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c3587c9815c004e712bb92 Subject: Re: [PHP-DEV] Argument unpacking - Multiple unpacks and trailing arguments From: nikita.ppv@gmail.com (Nikita Popov) --001a11c3587c9815c004e712bb92 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Sep 23, 2013 at 9:45 PM, Andrea Faulds wrote: > On 23/09/2013 20:33, Nikita Popov wrote: > > The main open question (or at least the focus of the discussion) seems to >> be whether to allow multiple unpacks and trailing arguments. >> >> > I'm not sure I like the idea of multiple unpacks, were we to implement > named parameters (if you did f(...(['a' => 2]), ...(['a' => 3])) you'd > presumably have the $a argument overridden?), but I can't oppose it for > linear arguments alone. > 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). > I'm not sure about trailing arguments either. I'm not sure if there's > really a good use case for them. > > I notice that we do not allow either in the variadics RFC, so I think it > would make sense to be consistent with that. 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. > If someone really needs to do either of these, it would be a simple > array_merge() away, and that might make the code clearer. > 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. I also note that Python doesn't allow either of these. I can't find why > exactly, but I would assume there were good reasons behind it. > Yes, Python doesn't allow this. Ruby also didn't allow this, but removed the restriction in MRI 1.9.1. I couldn't find any reasoning for either (i.e. why Python disallows it and why Ruby started allowing it). Nikita --001a11c3587c9815c004e712bb92--