I have a basic programming question. I would like to know if every non-void function should have an “return” statement in PHP script.
Take the following two example functions. Which one would be the better way to program? They both do the same thing (to my understanding) but which is the “better practice” and why?
function displayApple1($str){
if($str == 'apple')
echo $str;
}
function displayApple2($str){
if($str == 'apple')
echo $str;
else
return;
}
Overuse of
returnis a bad thing. Your execution paths should be simple and straightforward; overuse of thereturnkeyword can imply (improper) complexity.