Re: trying to do too much with functions?
| From: | Robby Russell | Date: | Thu, 02 Sep 2004 16:20:41 +0000 |
| Subject: | Re: trying to do too much with functions? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-195599@lists.php.net to get a copy of this message | ||
On Thu, 2004-09-02 at 07: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?
>
>
/**
* pass an array..so as long as you pass one thing...
*/
function doStuff($args)
{
// do something
print_r($args);
}
/**
* this arg is optional as it has a default value
*/
function doSomething($x=0)
{
return $x;
}
-Robby
--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robby@planetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
****************************************/
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc