Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68768 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23955 invoked from network); 30 Aug 2013 23:40:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 23:40:12 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.49 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.219.49 mail-oa0-f49.google.com Received: from [209.85.219.49] ([209.85.219.49:42319] helo=mail-oa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/84-00443-B5D21225 for ; Fri, 30 Aug 2013 19:40:11 -0400 Received: by mail-oa0-f49.google.com with SMTP id i7so3038495oag.36 for ; Fri, 30 Aug 2013 16:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=G6PHHeXsK8KgtugN2O8dSNChAQDlE1Ff+5briW6TTgQ=; b=SHfcjysPzGgf5SH1wuflKLEQqXcE4CJTOw0d+lpTd5AB+OFTr505lTBxVgFHfByh5g f2U0dTdHNCA9HM6nYYSASDQJh5qHnV82/x2zfT1cEcqPZb63fA2ztQ1FgagoqBjooOF3 kveQTguvL7MYC9Fwv4J+4HlL2uj8vsg68CFB7dkt3x3LCup12EDOE/qgb+WjgQMiv7cj 1iancgv+TrjIVEsW8Gn/x8rxmTkoIRZ4rH5zaPiCC6nH/iIgZfaxPDYPAADHV3qSbYBt RD81u+wEtP3i1zN7xa1CDZTFY4cob7d7JoCAFBFV0zrtFr6M7mIXNgla4DespJTsD5HJ 3tyw== X-Received: by 10.182.214.98 with SMTP id nz2mr8832646obc.37.1377906008757; Fri, 30 Aug 2013 16:40:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.100.6 with HTTP; Fri, 30 Aug 2013 16:39:48 -0700 (PDT) In-Reply-To: References: <5220CEDE.8080600@sugarcrm.com> <5220DA50.9020306@sugarcrm.com> <522113B1.8000605@sugarcrm.com> Date: Sat, 31 Aug 2013 01:39:48 +0200 Message-ID: To: Bob Weinand Cc: Malyshev Stas , Developers List PHP Mailing Content-Type: multipart/alternative; boundary=e89a8ff1cefe2f987804e532bea4 Subject: Re: [PHP-DEV] [RFC] Argument unpacking From: linepogl@gmail.com (Lazare Inepologlou) --e89a8ff1cefe2f987804e532bea4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2013/8/31 Bob Weinand > Hi! > > Am 31.8.2013 um 00:27 schrieb Lazare Inepologlou : > > > 2013/8/30 Stas Malyshev > > > >>> don't see a reason why one should explicitly disallow doing multiple > >>> unpacks. > >> > >> Because it makes very hard to understand what's going on and makes no > >> sense semantically. > >> > >>> As you can see, here two arguments are unpacked in one call. > >> > >> This is very special use case to be hidden in library functions, I don= 't > >> think we need to have language syntax specially directed at that, at t= he > >> cost of making it overall more complex and hard to understand. I can s= ee > >> what "add all those params at the end" syntax mean. However having > >> something like ($a, ...$b, $c, ...$d, $e, $f, $g, ...$h) I have no ide= a > >> what's going on at all and what is sent where. > >> > >> > > I agree with Stas here. If an argument comes after an unpacked array, i= ts > > position is not certain until runtime. This makes life difficult for > static > > analysis tools, which is one of the reasons for introducing the new > syntax. > > The alternative is for users to use what we have now: call_user_func_arra= y > with some array_merge, which makes it as difficult for static analysis as > the > new syntax does. This really is a non-argument. > > Please read carefully my argument. The alternative is to actually call the function normally with the arguments expanded in the code. In other words, the alternative to this: strpos( ...$array , 3 ); // which cannot be verified statically is this: strpos( $array[0] , $array[1] , 3 ); // which is perfectly verifiable. The power of this proposal is found when used with optional arguments (or variadic arguments) which always come last anyway. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel > And should we really restrict the user's code with some arbitrary limits? > It just makes the user use some really ugly hacks nobody wants to see. > > > Even in the use case of Nikita, the two arguments to be unpacked come > > without any standard arguments between or after them. > > > > I suggest that argument unpacking should be limited to the last argumen= ts > > only. > > An example where it really would make sense is: > > function long ($arg, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7, $string) { > // do something with your arguments > } > > // just instead of copying the seven parameters; increases readability > // and don't argue this would be badly statically analyzable - it is, but > this isn't > // the point. I want to show that people may find here some use case. > function short (...$args) { > if (count($args)) > return long(...$args, "some value"); > } > > > Lazare Inepologlou > > Ing=C3=A9nieur Logiciel > > > > > > > > -- > >> Stanislav Malyshev, Software Architect > >> SugarCRM: http://www.sugarcrm.com/ > >> (408)454-6900 ext. 227 > > I finally am in favor of the proposal, because it allows removing a lot o= f > ugly > call_user_func_array calls which aren't really well readable. (and > naturally > because it allows passing the variadic parameters if that rfc will be > accepted) > > And I think you are really arguing about non-issues. > Example: Multiple uses of unpacking syntax makes sense when you call a > function with a variadic parameter: > > function variadic (...$args) { > // do something > } > > variadic(...$array1, ...$array2); > > > Bob Weinand > > --e89a8ff1cefe2f987804e532bea4--