Weak logic operators

From: Date: Tue, 01 Apr 2014 13:24:33 +0000
Subject: Weak logic operators
Groups: php.internals 
Request: Send a blank email to internals+get-73501@lists.php.net to get a copy of this message
Heya, I wrote my question already on the general list but got no answer. Maybe someone on this list can help me out. I was 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 used it the last time. 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 do not really see the benefit of writing it this ways. I think the weak logic operators just add more complexity to the language and hence decrease maintenance. Moreover they are a source of confusion (should I use 'or' or || etc.). The situation for the operator 'xor' is even worse than for 'or' and 'and' in my opinion, since it has no short-circuit and one could use ^ instead of xor: $a = ( foo() xor bar() ); Could be written as follows: $b = foo() ^ bar(); So I am curious, are there other use cases out there that justify the existence of those operators? Cheers, Robert

« previous php.internals (#73501) next »