Possible Duplicate:
Why should a function have only one exit-point?
As a CS student I have had it beaten into my head that there should only be one exit point in a function, at the end.
eg. This:
function foo()
{
//do stuff here
if($bar)
{
$out = FALSE;
}
else
{
$out = TRUE;
}
return $out;
}
Not:
function foo()
{
//do stuff here
if($bar)
{
return FALSE;
}
return TRUE;
}
However I have seen this second type of exiting used quite often in other peoples code in php, and even in core code for some frameworks (like Kohana which I have been using lately). Is this method of exiting a function considered okay in php standards?
Edit: I can see why I have been told not to do it as it can be easier to track some problems in a function with one exit point, other times I can see why it should be allowed as other problems are better solved or tracked in functions with multiple exit points.
Edit 2: Added "do stuff here" comments to the code example to make people happy