I am sorry for posting a pretty redundant question. I was wondering if it was really necessary to use else {} if the code just stops or returns a value. In theory, is it really necessary to put else{} in these scenarios?
function check() {
if($something == "something") {
exit;
}
echo "hello";
}
Or
function check() {
if($something == "something") {
return true;
}
echo "hello";
}
The reason I posted this was because I saw some “professional” code which I guess they thought it looked “good.”
Syntactically, it’s perfectly fine.
It’s also a very common pattern to use, and IMHO, makes code more readable.
For the sake of code clarity/clean coding, if you’re returning a boolean you should return a boolean even if the if() doesn’t match.