Re: Multiple return statements in a function.

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

 



At 8:12 AM -0400 4/23/09, Peter van der Does wrote:
I tend to put my return value in a variable and at the end of the
function I have 1 return statement.
I have seen others doing returns in the middle of the function.

-snip-

What is your take? And is there any benefit to either method?

Peter van der Does

Peter:

It's called "Structured programming" -- one way in and one way out of a function.

There are, of course, exceptions where it might help others reviewing your code to see what's going on, such as returning a null value if the argument(s) provided are not suitable. But normally the rule is, do not provide an exit from a function in more than one place.

The "benefit" is easier to read code.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

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