Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21546 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36554 invoked by uid 1010); 15 Jan 2006 16:14:54 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 36539 invoked from network); 15 Jan 2006 16:14:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jan 2006 16:14:54 -0000 X-Host-Fingerprint: 82.94.239.5 jdi.jdi-ict.nl Linux 2.5 (sometimes 2.4) (4) Received: from ([82.94.239.5:52364] helo=jdi.jdi-ict.nl) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id D4/05-13436-CF47AC34 for ; Sun, 15 Jan 2006 11:14:52 -0500 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id k0FGEm2S018668; Sun, 15 Jan 2006 17:14:48 +0100 Received: from localhost (localhost [127.0.0.1]) by jdi.jdi-ict.nl (8.12.11/8.12.11) with ESMTP id k0FGEhu4018642; Sun, 15 Jan 2006 17:14:44 +0100 Date: Sun, 15 Jan 2006 17:14:39 +0100 (CET) X-X-Sender: derick@localhost To: Ron Korving cc: PHP Developers Mailing List In-Reply-To: Message-ID: References: <43C67431.9090003@prohost.org><3A366ACB-20D4-42C7-BBAE-46F643E3A91F@intuitivefuture.com><878581203.20060112153625@ionzoft.com> <7.0.0.16.2.20060112154219.029d06c8@zend.com><43C75FEE.7040908@php.net> <6C.F4.25674.EFD67C34@pb1.pair.com> <43C786E5.1020400@mysql.com> <43C7975A.2070504@php.net> <43C79801.7070101@mysql.com> <43C79A23.6010701@php.net> <43C79DC8.6000207@php.net> <43C79EE0.909@php.net> X-Face: "L'&?Ah3MYF@FB4hU'XhNhLB]222(Lbr2Y@F:GE[OO;"F5p>qtFBl|yVVA&D{A(g3[C}mG:199P+5C'v.M/u@Z\![0b:Mv.[l6[uWl' MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at jdi-ict.nl Subject: Re: [PHP-DEV] Re: Named arguments revisited From: derick@php.net (Derick Rethans) On Fri, 13 Jan 2006, Ron Korving wrote: > I think everybody should be open to a new way of dealing with functions. The > advantages apply to many many functions. Take for example: > > mysqli mysqli_connect ( [string host [, string username [, string passwd [, > string dbname [, int port [, string socket]]]]]] ) > > It would be nice to be able to do > $conn = mysqli_connect(host: $host, port: $port); > without having to worry about anything else than the parameters I care > about. You do know that that means that we have to consistently name all parameters to our 4000+ functions, right? Besides that road block, I don't see how: mysqli_connect(host: $host, port: $port); differs from: mysqli_connect( array( 'host' => $host, 'port' => $port ) ); (except that it's a bit more to type). If you're designing an API of your own you can easily design it in such a way that you don't have that many parameters anyway. A specific class accepting a lot of parameters can easily set them as default: setOptions( array( 'location' => $location ) ); $this->setOptions( $options ); } public function setOptions( array $configurationData ) { foreach ( $configurationData as $name => $value ) { switch ( $name ) { case 'location': if ( $value[strlen( $value ) - 1] != '/' ) { $value .= '/'; } $this->tsLocationPath = $value; break; case 'format': $this->tsFilenameFormat = $value; break; default: throw new ezcBaseSettingNotFoundException( $name ); } } } ?> You can even easily verify the parameters that you're passing for ranges etc. This is a cleaner API as it's easier to read, and definitely not harder to write. On top of that you get the benefit of value/range checking. The usage is then simply: or: "test-[LOCALE].xml' ) ); ?> or: setOptions( array( 'format' => "test-[LOCALE].xml' ) ); ?> > It's a new way of doing things, and that may be scary, but think how > useful this can be for programmers. When you call a function, the > order in which you present the function parameters is never > interesting, except for a few rare cases like printf(). But unlike > printf(), the functioning of a strpos() function doesn't require a > certain order in parameters. It requires a needle and a haystack. I would rather think it's less obvious about what is going on. You should always care in which order you pass arguments to normal functions, as otherwise you're getting inconsistencies in its usage all through your application. And I would not be happy to see: $blah = strpos( haystack: $string; needle: 'F' ); instead of: $blah = strpos( $string, 'F' ); regards, Derick -- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org