Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68754 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89157 invoked from network); 30 Aug 2013 19:03:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 19:03:25 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.178 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.128.178 mail-ve0-f178.google.com Received: from [209.85.128.178] ([209.85.128.178:60646] helo=mail-ve0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/1C-32511-B7CE0225 for ; Fri, 30 Aug 2013 15:03:24 -0400 Received: by mail-ve0-f178.google.com with SMTP id ox1so1630126veb.37 for ; Fri, 30 Aug 2013 12:03:20 -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=ir/4lQeSN56KdwdtJOG9la0Lb02aYrUqMTnHYIDQcJo=; b=RDABLnYQKRdijE9uyid0bHWezV5p6xI+ZGnoCgNR518DUmtyvdonciV/J+hmaxh1Ne GSz4gwohC3yrxdvXMDJG1WwxwZSI2tyVcVZ8eB3AcmAipKDmx9KPT7l5NOmdPtbhN0MT +2S5yNGTZ+ZkLhxk8oXgmz4RB/XrNU+vDzLexZ4zYevQTWHtvhlmRZSJhlqygqDBKnTm UfBx9O+t8oAPGDFegQUdUl0Mw1Fcw4kxj676yunuWfoWe8TP9rPWl2XYxTnVdHzGHgYJ lU18NlIwW2poDtnTLJCYEOkQtWdrmXbr+bvxXzhGJk4s994Kjg8FxUTBChDrzVFLVlEk zJPw== MIME-Version: 1.0 X-Received: by 10.58.108.8 with SMTP id hg8mr9192218veb.6.1377889400580; Fri, 30 Aug 2013 12:03:20 -0700 (PDT) Received: by 10.220.17.136 with HTTP; Fri, 30 Aug 2013 12:03:20 -0700 (PDT) In-Reply-To: <5220DA50.9020306@sugarcrm.com> References: <5220CEDE.8080600@sugarcrm.com> <5220DA50.9020306@sugarcrm.com> Date: Fri, 30 Aug 2013 21:03:20 +0200 Message-ID: To: Stas Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1130cec842f25104e52ee0a9 Subject: Re: [PHP-DEV] [RFC] Argument unpacking From: nikita.ppv@gmail.com (Nikita Popov) --001a1130cec842f25104e52ee0a9 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Aug 30, 2013 at 7:45 PM, Stas Malyshev wrote: > Hi! > > > Assuming you mean call_user_func_array, yes. This is just syntax sugar > > for call_user_func_array. Advantages of this syntax over cufa are > > outlined here: > > > https://wiki.php.net/rfc/argument_unpacking#advantages_over_call_user_func_array > > The only case that I see that could make sense is $db->query($query, > ...$params). > > Multiple unpackings make no sense to me, as it is impossible to know > which argument ends up where and no corresponding syntax exists on > function side. Also, no other language as far as I can see allows it. > Not sure I get what you mean. All languages with argument unpacking allow this. It's not commonly needed, but there are uses for it and I don't see a reason why one should explicitly disallow doing multiple unpacks. If you want a practical example for this, consider partial application, where you bind a number of arguments to a function. An "old-style" definition for this (no variadics syntax, no argument unpack) would look like this: function bind(callable $function) { $boundArgs = array_slice(func_get_args(), 1); return function() use ($function, $boundArgs) { return call_user_func_array( $function, array_merge($boundArgs, func_get_args() ); } } The equivalent new-style definition with variadics syntax and argument unpacking: function bind(callable $function, ...$boundArgs) { return function(...$args) use($function, $boundArgs) { return $function(...$boundArgs, ...$args); } } As you can see, here two arguments are unpacked in one call. > Also, I just noticed the RFC tries to sneak in the exception throwing > in the syntax construct, which we agreed not to do a long time ago and > which was never done in the engine. We shouldn't do this - if you want > to change PHP error handling, it should be in separate RFC for this > purpose. > I tried to make sure that this does not "sneak in" but is mentioned prominently (it's half of the by-ref section). Anyway, as already mentioned in the RFC: Exceptions are how we deal with errors relating to Traversables in general. Yes, also in the engine. E.g. in the foreach implementation, if get_iterator fails an exception is thrown: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_vm_def.h#4191 If staying consistent with foreach is not wanted (or this is not considered "consistent"), I'm also okay to turn that into a fatal error or into a warning where the argument will simply be passed without the reference-binding instead (like what we do when you pass a function call that returns by-value to a by-reference parameter. Though there it's actually just an E_STRICT.) Nikita --001a1130cec842f25104e52ee0a9--