Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20915 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87309 invoked by uid 1010); 30 Nov 2005 23:17:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 87293 invoked from network); 30 Nov 2005 23:17:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Nov 2005 23:17:01 -0000 X-Host-Fingerprint: 209.59.182.2 amplex.webserversystems.com Linux 2.4/2.6 Received: from ([209.59.182.2:33577] helo=amplex.webserversystems.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 2C/46-14828-CE23E834 for ; Wed, 30 Nov 2005 18:17:00 -0500 Received: from whitecockade.com ([64.142.12.177] helo=[192.168.0.9]) by amplex.webserversystems.com with esmtp (Exim 4.52) id 1EhbC0-0001op-4f; Wed, 30 Nov 2005 18:16:52 -0500 In-Reply-To: <374c2968dd7f3d13c696037ef850256f@gravitonic.com> References: <374c2968dd7f3d13c696037ef850256f@gravitonic.com> Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-ID: <88B45438-E185-49D9-8EDD-43FF8F54BF1C@intuitivefuture.com> Cc: internals@lists.php.net Content-Transfer-Encoding: 7bit Date: Wed, 30 Nov 2005 15:16:43 -0800 To: Andrei Zmievski X-Mailer: Apple Mail (2.746.2) X-Antivirus-Scanner: This message has been scanned by ClamAV - CLEAN. X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - amplex.webserversystems.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - intuitivefuture.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Named arguments revisited From: jared@intuitivefuture.com (Jared White) On Nov 30, 2005, at 1:50 PM, Andrei Zmievski wrote: > Can you explain your reasoning behind "essential for using PHP as a > solid templating language" and "nothing is a good substitute for > the real deal"? > > - Andrei OK, to take an example from Smarty, you could do a value cycle (for multi-row-color tables, etc.) with some extra parameters like so: {cycle name="myCycle" values="#eeeeee;#d0d0d0" print=false reset=true delimiter=";"} (I'm not a Smarty expert, so I apologize if I didn't get that quite right.) Now, if I wanted to express that with a PHP function currently, it might look like this: cycle("myCycle", "#eeeeee;#d0d0d0", false, true, ";"); My question is, what if you have no idea how the cycle function works, or you haven't used it in a while and temporarily forgot? Your two options are look at the source code (if possible) or look at the documentation (if it's any good). Whereas with named arguments, it's self-explanatory. cycle(name: "myCycle", values: "#eeeeee;#d0d0d0", print: false, reset: true, delimiter: ";"); (FYI: I just picked a colon for the heck of it...whatever operator is used isn't important to me.) Much, much clearer and obvious. Perhaps not such a big deal in "regular" PHP code blocks, but in an HTML/PHP mixed template type of scenario, the named arguments are so much nicer. Plus, if they're implemented in an order-agnostic fashion, you could reorder those arguments any way you like -- but I don't necessarily think that's its biggest selling point. Sure, you could use an array for this, like so: cycle(array("name" => "myCycle", "values" => "#eeeeee;#d0d0d0", "print" => false, "reset" => true", "delimiter" => ";")); But not only is that a lot more verbose and messy, but it provides no language features in the function/method definition itself, so you just have to hope the big array that comes in has the right stuff in it. Not ideal. Anyway, I hope that helps, and if you have any other thoughts or questions, please shoot away. Regards, Jared