On Fri, 11 Jan 2002 [EMAIL PROTECTED] wrote:
> ** Reply to note from Markus Fischer <[EMAIL PROTECTED]> 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.

There are two ways I can think of which would be sufficient solutions. The
first is the one you mention and the second is ADA style ability to
mention which argument is supposed to go to which parameter, e.g., foo(2
=> two, 3 => three, 4 => four).
I think the nicer solution would be the second one but I don't think it's
feasible to implement this without a very heavy price in performance (we
can't know at compile time like in ADA and therefore we'd need to do
logic/lookups/bookeeping at runtime).
The alternative solution of allowing foo(,,4) would work and can probably
be implemented easier (it might still lead to a tiny slow down but
probably negligable); however it does look kind of ugly and it'll be quite
confusing if there will be lots of commas.

We are probably best off leaving things the way they are and in the very
few cases where it is really needed to pass arrays. However, this should
really be the exception to the rule when there is no other alternative
because building the array and later on checking for values inside it is
much slower than regular parameter passing.

Andi


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to