Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68760 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8233 invoked from network); 30 Aug 2013 21:35:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 21:35:27 -0000 Authentication-Results: pb1.pair.com header.from=krebs.seb@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.174 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@gmail.com X-Host-Fingerprint: 74.125.82.174 mail-we0-f174.google.com Received: from [74.125.82.174] ([74.125.82.174:47670] helo=mail-we0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B5/71-00443-E1011225 for ; Fri, 30 Aug 2013 17:35:27 -0400 Received: by mail-we0-f174.google.com with SMTP id q54so2040366wes.19 for ; Fri, 30 Aug 2013 14:35:23 -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=tXjvPGt3bNVJNH8tgQ3lITpIL65SOi5QNghDazJ9ZGU=; b=tXu1sHwqf80yCc3kDfM9CVdjjRLcvCJyTV0TKSZyZmWKdvZDjoMrxGS9BBvIOtvLqw Iqh/OLzbtLZyP0prfVkps5iz4Je1SHXBIRTUsUeiJTJNz/fZi8LgZN91lQ19Xl/0wdk9 fiKMI86f6kmesbz2U9dbepJgc0fo3V+pNJli+a/lD2DhPlGBZ6TZJnwn2X+I7Noj1eWC fDwJam2Z0p4y70c/JQjfLwuVK21RqIFsj4t68yCnebnXzAAMFePdOhmkdVSfvBj2enjx 5q9eJK3muupHpb9Q9tu4pRH15mO9O/aN3TBqFKq5UJSanqqEEkfJFVEhu44WDCmGcDLX IS9A== X-Received: by 10.180.107.225 with SMTP id hf1mr4057845wib.7.1377898523323; Fri, 30 Aug 2013 14:35:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.5.9 with HTTP; Fri, 30 Aug 2013 14:34:43 -0700 (PDT) In-Reply-To: <893f9c06c8fe43188f9e4d09fc0594b7@BN1PR07MB135.namprd07.prod.outlook.com> References: <893f9c06c8fe43188f9e4d09fc0594b7@BN1PR07MB135.namprd07.prod.outlook.com> Date: Fri, 30 Aug 2013 23:34:43 +0200 Message-ID: To: "jbondc@openmv.com" Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=e89a8f3baedf04f61404e5310054 Subject: Re: [PHP-DEV] [RFC] Syntax for variadic functions From: krebs.seb@gmail.com (Sebastian Krebs) --e89a8f3baedf04f61404e5310054 Content-Type: text/plain; charset=ISO-8859-1 2013/8/30 jbondc@openmv.com > On Wed Aug 28 11:47 AM, Nikita Popov wrote: > > > > https://wiki.php.net/rfc/variadics > > Interesting idea, expanding on: > > function log($message, ...$options) {} > > It would seem convenient to allow ...$options to be passed as a key-value > array of arguments as well: > function logA($message, ...$options[]) { echo count($options); } > > logA("foo"); // 0 > logA("foo", 1, 2); // 2 > logA("foo", array(1,2,3)); // 3 > > The difference here is that variadic options is declared as an optional > array, it would not support a 'typehint' forcing all arguments to be of the > same type. > It could be a way to support ~ named parameters > > // requires at least 1 argument named as 'level' > function logB($message, ...$options['level']) { > echo $options['level'] .' '. count($options); > } > > logB("foo"); // fails: 'level' argument > missing > logB("foo", 'notice'); //notice 1 > logB("foo", ['level' => 'notice']); // notice 1 > logB("foo", 'notice', 'extra'); // notice 2 > logB("foo", ['level' => 'notice'], 'extra'); // notice 2 > > // requires min 2 arguments > function logC($message, ...$options['level','priority']) { > echo 'level:'. $options['level']; > echo 'priority:'. $options['priority']; > } > logC("foo", "notice", 4); > logC("foo", ['level' => 'notice', 'priority' => 4]); > > That would remove the need for a "splat" or "scatter" operator. The > declaration "...$options[]" would mean, I accept an array of arguments > followed by extra arguments > I'd recommend to use an object, or separate parameters instead. Thats not a use-case for argument-lists. Regards Sebastian > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- github.com/KingCrunch --e89a8f3baedf04f61404e5310054--