Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47821 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8595 invoked from network); 7 Apr 2010 14:16:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2010 14:16:15 -0000 Authentication-Results: pb1.pair.com header.from=cschneid@cschneid.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=cschneid@cschneid.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cschneid.com from 195.226.6.51 cause and error) X-PHP-List-Original-Sender: cschneid@cschneid.com X-Host-Fingerprint: 195.226.6.51 darkcity.gna.ch Linux 2.6 Received: from [195.226.6.51] ([195.226.6.51:59162] helo=mail.gna.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8C/73-20534-AA39CBB4 for ; Wed, 07 Apr 2010 10:16:11 -0400 Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id D83D4177705; Wed, 7 Apr 2010 16:16:07 +0200 (CEST) X-Virus-Scanned: amavisd-new at gna.ch Received: from mail.gna.ch ([127.0.0.1]) by localhost (gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nW1U5lD7r70j; Wed, 7 Apr 2010 16:16:07 +0200 (CEST) Received: from [192.168.1.72] (gw-search.cyberlink.ch [212.55.194.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 4612D139253; Wed, 7 Apr 2010 16:16:07 +0200 (CEST) Message-ID: <4BBC93A6.6010806@cschneid.com> Date: Wed, 07 Apr 2010 16:16:06 +0200 User-Agent: Thunderbird 2.0.0.24 (X11/20100302) MIME-Version: 1.0 To: Tjerk Anne Meesters CC: internals@lists.php.net References: <745C5243-EB51-4D43-B036-8A34CDBBB547@gregory.net> <4BB68D61.2070301@lerdorf.com> <4BB6938F.7090404@zend.com> <4BB90DB7.6060706@zend.com> <4BBC25DD.7060604@divbyzero.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Named Parameters From: cschneid@cschneid.com (Christian Schneider) Tjerk Anne Meesters wrote: > In the case whereby names parameters are "plucked" from the argument > list and passed as a hash to the function it really shouldn't matter > whether that's invalid in python; both (2, 'name' => 'test') and > ('name' => 'test', 2) would yield the same results, albeit it's a > highly dubious way of passing arguments ;-) Actually we use "positional" (scalar) both after and before "named" (associative) parameters a lot for HTML generation and DB queries: $html = table('class' => "beautiful", tr( td("foo"), td("bar"), ), tr( td("qux"), td("quux"), ), ); foreach (new T_User('firstname' => $firstname, "ORDER BY age") as $user) ... $bar = it::replace('Foo' => "Bar", $foo, 'casesensitive' => true); So any solution restricting named parameters to any of - declared named parameters only - not allowing alternating named/positional parameter sets while maintaining these sets and order would not fit our needs. As a result our patch (and syntax converter in both directions for unpatched webservers) uses a simple but somewhat limited approach: Any sequence of key => value pairs in a function call are surrounded by array() (done at compile time). This means functions accepting interleaved named/non-named parameters need to do some varargs parsing and sometimes you need to still manually add array() if you want to separate two sets of named parameters (but that's a questionable API in most cases). More info: http://cschneid.com/php/INFO_README Patch and manual converter: http://cschneid.com/php/ Autoloader with automatic syntax conversion: http://itools.search.ch/ I know I've mentioned this here before but I still think its pros and cons should be taken into consideration when talking about this subject, - Chris