Re: Boolean Parameter to 3 Options?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Why not this:

function doFooBar($doFoo = 0)
   {
   switch ($doFoo) {
       case 2:
            echo "Did Baz";
        break;
       case 1:
            echo "Did Foo";
        break;
        default:
            echo "Did Bar";
        break;
    }
}

I think in this way you can avoid future problems in case you need to add 
other options in this param.

Hope helps.


"Matt Neimeyer" <matt@xxxxxxxxxxxx> escreveu na mensagem 
news:9077339e0904290942y542c7978neb1cd92af56563fa@xxxxxxxxxxxxxxxxx
>I have a function that currently takes a boolean value as a parameter.
> But now I want to expand it to 3 options...  So if I have...
>
> function doFooBar($doFoo = false)
>   {
>   if($doFoo)
>      { echo "Did Foo"; }
>   else
>      { echo "Did Bar"; }
>   }
>
> Is it as "simple" as changing it like follows to avoid having to
> change existing code that won't use the new values.
>
> function doFooBar($doFoo = 0)
>   {
>   if($doFoo == 2)
>      { echo "Did Baz"; }
>   else if($doFoo == 1)
>      { echo "Did Foo"; }
>   else
>      { echo "Did Bar"; }
>   }
>
> Something about that disturbs me. Perhaps because any time I think "Oh
> it will be as simple as..." it usually isn't.
>
> Thanks in advance!
>
> Matt 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux