Personally, I hate trailing {'s

I think this

function blah()
{
   switch( $bob )
   {
      case 1:
         $var = "whatever";
      break;
   }
}

Is much easier to read and follow.  As for the exiting question...

The "proper" way is to use the breaks.  "They" say that multiple returns in
any function = bad programming.  The .0001 second that it takes to break and
return the value will never matter.

Plus, you or someone else may have to add to that function later.  Let's say
I wanted to add "</B>" to the end of $retval.  If you use the normal way I
can just make one change, return $retval . "</B>"; instead of changing 3
different returns.

SL.



----- Original Message -----
From: "Boget, Chris" <[EMAIL PROTECTED]>
To: "Php (E-mail)" <[EMAIL PROTECTED]>
Sent: Thursday, April 19, 2001 11:57 AM
Subject: [PHP] Which is better coding style...


> Which is better?
>
> function blah() {
>   switch( $bob ) {
>     case 1:
>        return "this";
>
>     case 2:
>       return "that";
>
>     default:
>       return "other";
>
>   }
> }
>
> function blah() {
>   $retval = "";
>
>   switch( $bob ) {
>     case 1:
>        $retval = "this";
>        break;
>
>     case 2:
>       $retval = "that";
>        break;
>
>     default:
>       $retval = "other";
>        break;
>
>   }
>
>   return $retval;
>
> }
>
>
> In other words, is it good practice to exit out of a block (any
> block... not just switch; if, for, while) prematurely as demon-
> strated in the first example?  Or should you do it as demon-
> strated in the second example?
>
> Chris
>


-- 
PHP General 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