Hi There,
this code:
function returnit($val){
if($val==6){ echo 'oops!'; exit; }else{ return $val; }
}
//now execute the | logical operator
if($a=returnit(5) | $a=returnit(6)){
echo $a;
}
Doesn't echo 5, it's obvious that BOTH logical conditions are checked.
HOWEVER, this code:
function returnit($val){
if($val==6){ echo 'oops!'; exit; }else{ return $val; }
}
//now execute the || logical operator
if($a=returnit(5) || $a=returnit(6)){
echo $a;
}
Doesn't echo 5, instead it echos 1.
Now finally, this code:
function returnit($val){
if($val==6){ echo 'oops!'; exit; }else{ return $val; }
}
//now execute the OR logical operator
if($a=returnit(5) OR $a=returnit(6)){
echo $a;
}
Echos 5 like I'd expect (BTW I never write out OR anymore before this).
What's driving me crazy is, why is the second case with the || short circuiting like it's supposed to but the echo value turns to 1? I use || a lot in my code, very rarely for short-cicuiting, but would like to understand the language.
By the way I did search through the PHP documentation and I couldn't find anything on this.
Sam