Re: consistent way to handle structs
| From: | php4 at developersdesk dot com | Date: | Fri, 11 Jan 2002 16:42:35 +0000 |
| Subject: | Re: consistent way to handle structs | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-76716@lists.php.net to get a copy of this message | ||
** Reply to note from Markus Fischer <mfischer@guru.josefine.at> Fri, 11 Jan 2002 12:48:15
+0100
>
> What other way do we have to specify arbitray optional parameters
> without an ordering? Teh disadvantage of optional parmeters is when
> you need to only set the last one, you'll have to define all
> preceding optional parameters too.
Consider allowing this:
function foo( $one=1, $two=2, $three=3 ) {
echo "$one $two, $three";
}
foo( ,,5 ); # prints: 1 2 5
No value between commas in the parm list says take the default.
Required params must be filled in, but not specifying a value for an
optional parm takes the default from the function header.
It still requires the parms to be in the correct order, but you can
pick and chose which optional parms you want non-default values for.
The disadvantage is having to have the right number of commas before
your values, but at least you don't have to list all the defaults. (and
prevent yourself from being able to change a default just by changing
the function itself.)
The idea is stolen from HP's MPE operating system which I was sorry to
see depreciated recently.
Rick
Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com