On Thursday 02 September 2004 22:11, Justin French wrote: > 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?
Some languages handle it gracefully by allowing you to specify the parameters name and value when calling the function. AFAIK using arrays is the only way of emulating such a behaviour in PHP. Doing so allows you to easily extend a function's functionality and also not having to worry about order of parameters etc. Just look at how many of PHP's own functions have been extended over the years. And at least one of them have had the parameters switched around. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* Regarding astral projection, Woody Allen once wrote, "This is not a bad way to travel, although there is usually a half-hour wait for luggage." */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php