Re: Re: Named Parameters
| From: | Christian Schneider | Date: | Mon, 12 Apr 2010 14:43:38 +0000 |
| Subject: | Re: Re: Named Parameters | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-47894@lists.php.net to get a copy of this message | ||
Lars Schultz wrote:
> As I am using it now:
> function foo($x,$y,$options=array()){
> if ( !isset($options['opt1']) ) $options['opt1'] = 'foo';
> if ( !isset($options['opt2']) ) $options['opt2'] = 'bar';
> /* 1 */
> }
One little trick you can use to make things a bit more elegant right now:
function foo($x, $y, $options=array()) {
$options += array(
'opt1' => 'foo',
'opt2' => 'bar',
);
...
}
We're using this approach and since it's always right at the beginning
of the function it also servers as sort of a documentation being a bit
more concise, readable and less in danger of copy/paste errors than your
version.
Regards,
- Chris