Robert Stoll
2014-03-25 00:11:35 UTC
Heya,
I was just wondering for what reason PHP has weak logic operators.
So far I have only used the weak logic operator 'or' in the following situation:
foo() or die("nooo");
And it is quite a long time ago I have use it this way. You could also write the following instead:
if(!foo()){
die("noooo");
}
I am aware of that one can use 'or' and 'and' as substitute for || and && if using brackets in addition:
$a = ( foo() and bar() );
But I don't really see the benefit of that except that there is no alternative for xor. So the following could make
sense - I have never used it though:
$a = ( foo() xor bar() );
So I am curious, are there other use cases out there?
Cheers,
Robert
I was just wondering for what reason PHP has weak logic operators.
So far I have only used the weak logic operator 'or' in the following situation:
foo() or die("nooo");
And it is quite a long time ago I have use it this way. You could also write the following instead:
if(!foo()){
die("noooo");
}
I am aware of that one can use 'or' and 'and' as substitute for || and && if using brackets in addition:
$a = ( foo() and bar() );
But I don't really see the benefit of that except that there is no alternative for xor. So the following could make
sense - I have never used it though:
$a = ( foo() xor bar() );
So I am curious, are there other use cases out there?
Cheers,
Robert