"Justin French" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have a few functions with way too many parameters in them, or
> functions which have a non-obvious order of parameters which I
> constantly have to refer to as I'm working.  Since I'm using PHP as my
> templating language (none smarty here!) as well as the programming
> language.  So I've been looking for some alternatives...
>
> My main objectives:
>
>    1.  have all parameters optional
>    2.  have a mixed order for the paramaters
>
> Other languages seem to do this well (Ruby, or perhaps RubyOnRails
> seems good at it), but in PHP I can only see a few options... I'm
> hoping someone might offer a few more ideas.
>
> <? $params = array('a'=>'123','b'=>'456'); echo doStuff($params); ?>
> <?=doStuff(array('a'=>'123','b'=>'456'))?>
> <?=doStuff('a=123','b=456')?>
> <?=doStuff('a','123','b','456'); ?>
> <?=doStuff("a='123' b='456'")?>
>
> So, is that it?  Have I thought of all possible options?

As you should have a fixed parameter order in your function you don't need
to pass the variable names in. So this is OK for up to three or four params:
doStuff('value1', 'value2', 'value3', 'value4');

If your function takes more than four parameters an associative array would
be the way to go (your first example). You might consider splitting it up
into several functions if it takes that many arguments.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to