Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 21688 invoked from network); 30 Sep 2013 12:57:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Sep 2013 12:57:02 -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.220.176 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:45247] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/30-19753-D1579425 for ; Mon, 30 Sep 2013 08:57:01 -0400 Received: by mail-vc0-f176.google.com with SMTP id lf11so3687909vcb.7 for ; Mon, 30 Sep 2013 05:56:58 -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=tbgY9ibeDqpS4awJ8ZTcJwm25e5iKoUSG/jyT/v2P40=; b=yo7hQ4XZrM23Weuw+dcM5Gm8w7FqTVBJsy4y6k8w1gJlOdhoORg/LTmKMfBTAD0hy6 bV9xHt5skkMovzfs15C1NiaoBKyRWw2Uq5QOaTDsbT3vqAmZCYKY4Cs9XlEpa33Ha4oE zPs7WTsR44CaD++6HbwfXFsMPJDmTDh19lCSOcAF29StaIrwt/dzJoC9Is+MjJDyfmcR U4IrZ1DkwJ/kBMolDVCudax3GpxTQmIXfRJoFzF8mqcG/r7X1n/YDcad2lpR3r/fO+lT hXpoFZUSYDq+Wnf6h4gHf/2+YYRNmpyKhIShqJ3Mgto4nBGXZYSjNCtF3OvRw/MlcaaN wAog== MIME-Version: 1.0 X-Received: by 10.220.144.68 with SMTP id y4mr377470vcu.28.1380545818728; Mon, 30 Sep 2013 05:56:58 -0700 (PDT) Received: by 10.220.59.1 with HTTP; Mon, 30 Sep 2013 05:56:58 -0700 (PDT) In-Reply-To: <004a01ceb8a2$7a586830$6f093890$@tutteli.ch> References: <69BCC163-7988-4EBB-A817-5F5007EC924C@strojny.net> <004a01ceb8a2$7a586830$6f093890$@tutteli.ch> Date: Mon, 30 Sep 2013 14:56:58 +0200 Message-ID: To: Robert Stoll Cc: Lars Strojny , PHP internals Content-Type: multipart/alternative; boundary=047d7b33db441f250004e7995f9b Subject: Re: [PHP-DEV] Argument unpacking - Multiple unpacks and trailing arguments From: nikita.ppv@gmail.com (Nikita Popov) --047d7b33db441f250004e7995f9b Content-Type: text/plain; charset=ISO-8859-1 On Mon, Sep 23, 2013 at 11:18 PM, Robert Stoll wrote: > 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 > Introducing such a restriction doesn't make sense. A large number of uses (you might even say "most of the uses") of call_user_func_array is in call forwarding. In such cases the target function is usually not variadic. Also don't forget that PHP always supported variadics via func_get_args() and I'd like to continue supporting that style as well. Anything that tries to match up the unpack with a variadic arguments drop the utility of this feature to about zero. > 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. > Sorry, I don't understand what you're saying here. Unless your $iterator is some weird "output random stuff"-iterator, I don't see why the arguments to $foo and $bar would be different. If $iterator is a one-time iterator, the second call will simply fail (just like any time when you use a one-time iterator twice...) Nikita --047d7b33db441f250004e7995f9b--