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 return
is a bad thing. Your execution paths should be simple and straightforward; overuse of the return
keyword can imply (improper) complexity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With