Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68853 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78043 invoked from network); 2 Sep 2013 16:04:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2013 16:04:19 -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.204 as permitted sender) X-PHP-List-Original-Sender: jbondc@gdesolutions.com X-Host-Fingerprint: 207.46.163.204 mail-bl2lp0204.outbound.protection.outlook.com Received: from [207.46.163.204] ([207.46.163.204:20331] helo=na01-bl2-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/59-29856-007B4225 for ; Mon, 02 Sep 2013 12:04:18 -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; Mon, 2 Sep 2013 16:04:12 +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; Mon, 2 Sep 2013 16:04:12 +0000 To: Sebastian Krebs , Pierre Joye CC: Stas Malyshev , PHP Internals Thread-Topic: [PHP-DEV] [RFC] Skipping parameters take 2 Thread-Index: AQHOp6yM4alq4mUdOECKJoiZumCmoZmyYZEAgAAFtQCAACKI8A== Sender: Jonathan Bond-Caron Date: Mon, 2 Sep 2013 16:04:11 +0000 Message-ID: References: <52243BA6.5040905@sugarcrm.com> 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: 0957AD37A0 x-forefront-antispam-report: SFV:NSPM;SFS:(24454002)(51704005)(199002)(189002)(479174003)(377454003)(26614003)(74876001)(66066001)(56776001)(81816001)(53806001)(65816001)(56816003)(15202345003)(80976001)(77096001)(80022001)(74316001)(69226001)(54316002)(76482001)(77982001)(59766001)(31966008)(83072001)(74706001)(47446002)(74662001)(74502001)(54356001)(16799955002)(561944002)(79102001)(63696002)(81342001)(15975445006)(49866001)(50986001)(47976001)(47736001)(4396001)(74366001)(19580405001)(83322001)(81686001)(19580395003)(76576001)(51856001)(76786001)(46102001)(81542001)(33646001)(76796001)(24736002)(42882001);DIR:OUT;SFP:;SCL:1;SRVR:BN1PR07MB133;H:BN1PR07MB135.namprd07.prod.outlook.com;CLIP:24.201.92.93;RD:InfoNoRecords;A:1;MX: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] Skipping parameters take 2 From: jbondc@openmv.com ("jbondc@openmv.com") On Mon Sep 2 08:52 AM, Sebastian Krebs wrote: > 2013/9/2 Pierre Joye >=20 > > > > > > Any comments or feedback on the RFCs and the code are welcome, > > > especially pointing out the cases where it may not work (which means > > > we need more phpt's there :) > > > > Using default instead of ,,, is indeed much more readable. > > > > However I still wonder what prevents to finally implement named > > parameters too, it will provide the same feature while being even more > > handy and easier. >=20 >=20 > And it covers an additional use-case: Self-explaning parameters like in > "foo(is_strict =3D false)" instead of "foo(null, null, false)". >=20 >=20 Lots of overlap between variadic functions, this proposal & named parameter= s. A popular use case for library authors is to use: interface foo { function formatUseCases(array $options); } - Advantage: No dependency on a class / object - Disadvantage: doesn't document what options are available, hard to extend= 'default parameters' interface foo { function formatUseCases(MyOptions $options); } - Advantage: documents which options are available, easy to extend default = parameters - Disadvantage: modification of the object means these 'options' are availa= ble to any declaration using it, hard to maintain over time without big ref= actoring (lots of options objects) interface foo { function formatUseCases(...$options); } - Advantage: No dependency on a class / object - Disadvantage: doesn't document what options are available, no default par= ameters interface foo { function formatUseCases($showGood =3D true, $showBad =3D true, $pretty = =3D true, $title=3D "what are these parameters?"); } - Advantage: Self-documenting with default parameters - Disadvantage: Not extendable api signature (changing default parameters) - Readability: # array formatUseCases(['showGood': true, 'showBad': true, 'pretty': true]); #object $obj->showGood =3D true; $obj->showBad =3D true; $obj->pretty =3D true; formatUseCases($obj); # variadic or function declaration formatUseCases(true, true, true, "what are these parameters?"); - Solution somewhat as a hybrid? interface foo { function formatUseCases(...$options[showGood =3D true, showBad =3D true, = pretty =3D true, title=3D "what are these parameters?"]); } formatUseCases(true, true, true, "use defaults for everything else"); formatUseCases(['title': "use defaults for everything else"]); // more read= able Implemention wise $options could be ~ SplParameters which implements ArrayI= nterface : class bar implements foo { function formatUseCases(...$options[]) { // api signature as $options[] a= lways accepted (uses default params) echo get_class($options); // SplParameters var_dump($options['showGood']) // true; var_dump($options->showGood) // true; } } class bar2 implements foo { function formatUseCases(...$options[showGood =3D false]) { // easy to ext= end default options var_dump($options['showGood']) // false; } } Why use special syntax ~ "...$options[]" instead of just named parameters: http://msdn.microsoft.com/en-us/library/dd264739.aspx My hunch is that applying named parameters to every function would be very = costly in PHP. But as a special syntax applied to a few functions, this mig= ht work well.