Is it good to explicitly ‘return FALSE’ in a Boolean function or just ‘return TRUE’
Example A:
function check($link){
if(isset($link)){
return TRUE;
}else{
return FALSE;
}
OR
Example B:
function check($link){
if(isset($link)){
return TRUE;
}
By default php functions return FALSE, so is it good if I mention return FALSE or ignore it as Example B
so if im checking whether its true or false
if(check('eqweqw')){
echo 'its set';
}else{
echo 'its not';
}
Example A is better practice because it explicitly states the intention of your code. If someone reading your code doesn’t know that FALSE is returned by default, they’ll probably assume your code is buggy.
Remember: write code so it can be easily read and understood by others.