Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68996 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31269 invoked from network); 11 Sep 2013 12:16:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Sep 2013 12:16:13 -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.242 as permitted sender) X-PHP-List-Original-Sender: jbondc@gdesolutions.com X-Host-Fingerprint: 207.46.163.242 mail-by2lp0242.outbound.protection.outlook.com Received: from [207.46.163.242] ([207.46.163.242:3690] helo=na01-by2-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 19/52-15730-90F50325 for ; Wed, 11 Sep 2013 08:16:11 -0400 Received: from BN1PR07MB135.namprd07.prod.outlook.com (10.242.216.22) by BN1PR07MB136.namprd07.prod.outlook.com (10.242.216.14) with Microsoft SMTP Server (TLS) id 15.0.745.25; Wed, 11 Sep 2013 12:16:03 +0000 Received: from BN1PR07MB135.namprd07.prod.outlook.com ([169.254.15.119]) by BN1PR07MB135.namprd07.prod.outlook.com ([169.254.15.119]) with mapi id 15.00.0745.000; Wed, 11 Sep 2013 12:16:03 +0000 To: Nikita Popov , PHP internals Thread-Topic: [PHP-DEV] Re: [RFC] Named parameters Thread-Index: AQHOrZZ/S59eH1tvtEum/HBc3NuaTJm+zhzw Sender: Jonathan Bond-Caron Date: Wed, 11 Sep 2013 12:16:03 +0000 Message-ID: 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: 09669DB681 x-forefront-antispam-report: SFV:NSPM;SFS:(377454003)(51704005)(24454002)(189002)(199002)(51856001)(76796001)(74706001)(31966008)(15975445006)(59766001)(74662001)(81686001)(76576001)(76786001)(74502001)(19580395003)(47446002)(54316002)(76482001)(83322001)(81342001)(77982001)(47976001)(33646001)(4396001)(50986001)(47736001)(49866001)(81542001)(46102001)(63696002)(79102001)(80976001)(66066001)(15202345003)(56816003)(77096001)(80022001)(83072001)(65816001)(74316001)(56776001)(69226001)(53806001)(561944002)(74876001)(81816001)(74366001)(54356001)(24736002)(42882001);DIR:OUT;SFP:;SCL:1;SRVR:BN1PR07MB136;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] Re: [RFC] Named parameters From: jbondc@openmv.com ("jbondc@openmv.com") On Mon Sep 9 03:18 PM, Nikita Popov wrote: > > I created an RFC and preliminary implementation for named parameters: > > > > https://wiki.php.net/rfc/named_params > > >=20 Awesome work! >=20 > Let only special functions accept named params > ----- >=20 Proposal makes sense though there's still the challenge how to deal with th= e 'api mismatch' problem. I'm still undecided about 'mixing' positional & named arguments: An example use case for **kwargs here: http://www.python-requests.org/en/latest/api/ If you declare: request($method, $url, ...$args) Would $args collect 'method' and 'url' ? request(method =3D> 'post', url =3D> 'foo/'); > Renaming of parameters in signatures > ----- >=20 > Until now three options were discussed: > 1. Throw an E_STRICT (or similar) error during signature validation if a= parameter > is renamed 2. Don't validate parameter renames in signature and just let= people > hit the runtime error when they do the call. > 3. Create an ini-setting chooses either behavior 1 or 2. >=20 > class A { > public function foo($oldBar) { ... } > } > and > class B extends A { > public function foo($newBar) { ... } > } My preference would be to only support named parameters based on the initia= l declaration $oldBar (much simpler expectations). $c =3D new B; $c->foo(oldBar =3D> 'hello'); $c->foo(newBar =3D> 'hello'); // Warning, no named parameter 'newBar' found= , Warning first argument missing ... Lastly, using the same syntax "..." for declaring variadics and "unpacking"= seems odd to me.=20 Some ideas for a different syntax: $params =3D ['oldBar' =3D> 'hello']; $c->foo($params...); $c->foo((var)$params); $c->foo((...)$params); My preference is the third since it looks like we're casting an array to na= med parameters.