Possible duplicate:
Why should a function have only one exit point?
As a CS student, it hit me in the head that there should be only one exit point at the end.
eg. It:
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 saw that this second type of exit was used quite often in the code of other people in php and even in the main code for some frameworks (for example, Kohana, which I used recently). Is this method of exiting a function considered acceptable in php standards?
Edit: I see why I was told not to do this, since it will be easier to track some problems in a function with one exit point, sometimes I see why this should be resolved, since other problems are better solved or tracked in functions with multiple exit points .
Edit 2: added βmake stuff hereβ comments in the sample code to make people happy
source share