Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 594 invoked from network); 30 Aug 2013 20:34:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Aug 2013 20:34:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=jbondc@gdesolutions.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jbondc@gdesolutions.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gdesolutions.com designates 207.46.163.149 as permitted sender) X-PHP-List-Original-Sender: jbondc@gdesolutions.com X-Host-Fingerprint: 207.46.163.149 mail-bn1lp0149.outbound.protection.outlook.com Received: from [207.46.163.149] ([207.46.163.149:16488] helo=na01-bn1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/00-00443-BD101225 for ; Fri, 30 Aug 2013 16:34:36 -0400 Received: from BN1PR07MB135.namprd07.prod.outlook.com (10.242.216.22) by BN1PR07MB133.namprd07.prod.outlook.com (10.242.216.19) with Microsoft SMTP Server (TLS) id 15.0.745.25; Fri, 30 Aug 2013 20:34:31 +0000 Received: from BN1PR07MB135.namprd07.prod.outlook.com ([169.254.15.38]) by BN1PR07MB135.namprd07.prod.outlook.com ([169.254.15.38]) with mapi id 15.00.0745.000; Fri, 30 Aug 2013 20:34:31 +0000 To: Nikita Popov , PHP internals Thread-Topic: [PHP-DEV] [RFC] Syntax for variadic functions Thread-Index: AQHOpAXkkilRxznk50aUNT4kTlsA+5mshaRw Sender: Jonathan Bond-Caron Date: Fri, 30 Aug 2013 20:34:30 +0000 Message-ID: <893f9c06c8fe43188f9e4d09fc0594b7@BN1PR07MB135.namprd07.prod.outlook.com> References: In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [24.201.92.93] x-forefront-prvs: 0954EE4910 x-forefront-antispam-report: SFV:NSPM;SFS:(51704005)(377454003)(189002)(199002)(24454002)(69226001)(65816001)(79102001)(59766001)(77982001)(80022001)(63696002)(53806001)(56816003)(77096001)(66066001)(80976001)(76482001)(54356001)(54316002)(56776001)(4396001)(83072001)(81342001)(47976001)(50986001)(47736001)(83322001)(81542001)(19580395003)(51856001)(49866001)(31966008)(47446002)(74502001)(74662001)(46102001)(15975445006)(81816001)(76796001)(76786001)(81686001)(74706001)(74316001)(74366001)(74876001)(33646001)(76576001)(42882001)(24736002);DIR:OUT;SFP:;SCL:1;SRVR:BN1PR07MB133;H:BN1PR07MB135.namprd07.prod.outlook.com;CLIP:24.201.92.93;RD:InfoNoRecords;MX:1;A:1;LANG:en; Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: gdesolutions.com Subject: RE: [PHP-DEV] [RFC] Syntax for variadic functions From: jbondc@openmv.com ("jbondc@openmv.com") On Wed Aug 28 11:47 AM, Nikita Popov wrote: >=20 > https://wiki.php.net/rfc/variadics=20 Interesting idea, expanding on: function log($message, ...$options) {} It would seem convenient to allow ...$options to be passed as a key-value a= rray 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 arr= ay, it would not support a 'typehint' forcing all arguments to be of the sa= me 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' =3D> 'notice']); // notice 1 logB("foo", 'notice', 'extra'); // notice 2 logB("foo", ['level' =3D> '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); =20 logC("foo", ['level' =3D> 'notice', 'priority' =3D> 4]); That would remove the need for a "splat" or "scatter" operator. The declara= tion "...$options[]" would mean, I accept an array of arguments followed by= extra arguments