Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20933 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56623 invoked by uid 1010); 1 Dec 2005 07:45:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56607 invoked from network); 1 Dec 2005 07:45:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2005 07:45:29 -0000 X-Host-Fingerprint: 195.225.34.5 fw01.axit.nl Received: from ([195.225.34.5:20689] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 23/98-14828-81AAE834 for ; Thu, 01 Dec 2005 02:45:29 -0500 Message-ID: <23.98.14828.81AAE834@pb1.pair.com> To: internals@lists.php.net References: <374c2968dd7f3d13c696037ef850256f@gravitonic.com> <2D.57.14828.3453E834@pb1.pair.com> Date: Thu, 1 Dec 2005 08:45:09 +0100 Lines: 84 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Response X-Posted-By: 195.225.34.5 Subject: Re: [PHP-DEV] Named arguments revisited From: r.korving@xit.nl ("Ron Korving") You could use an associative array, but then you have a not-so-clean syntax and you have to handle default values for missing parameters yourself. Named parameter example: Traditional named example: 'root', 'password' => 'abcdefg', 'superuser' => true)); ?> You see the big advantages of named parameters? - clean syntax - no array handling inside the function or method - no checking on the existance or non-existance of parameters - no forcing default values for missing parameters - when you need to skip a parameter, you no longer have to give it's default value when calling the function, you can simply skip the whole parameter: function foo(bar: $bar=0, bla: $bla='test', cow: $moo='moooo'); call: foo(cow: 'test'); foo(0, 'test', 'test'); Named parameters would kick serious butt :) - Ron "Bart de Boer" schreef in bericht news:2D.57.14828.3453E834@pb1.pair.com... > Hi Jared, > > If probably don't understand named arguments correclty but couldn't you do > something like: > > function(array('name1' => 'val1', 'name2' => $var)); > > In the function you could then check which keys (names) have values, > thereby simulating a form of named agruments? > > > >> On Nov 29, 2005, at 11:17 PM, Jared White wrote: >> >>> Named arguments are absolutely essential for using PHP as a solid >>> templating language, and, in fact, they also greatly enhance code >>> readability for complex method calls of in-depth APIs. My experience >>> with both Objective-C and Python has showed me the wonders and joys of >>> named arguments, and it is something I've desperately wanted in PHP for >>> ages. I'm sure I'm not alone in this. I've tried array constructs, >>> multiple arguments with string-based names and fancy parsing using >>> func_get_args(), and various combinations thereof, and nothing is a good >>> substitute for the real deal.