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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to