It is very rare that I have seen some code that employs the PHP XOR logical operator. It is not the case that it is not required or programmers are unfamiliar with it; it probably seems that most programmers have become comfortable with using the more common ‘&&’ and ‘||’ operators to construct all logical comparisons; the XOR operator relegated to the subconscious black hole.
Take the following artificial example. We want to check if only one of the directories – either ‘$dir1’ or ‘$dir2’, but not both exists. The code using only the logical ‘&&’ , ‘||’ and ‘!’ operators is shown below.
The code obviously looks confusing, which we could easily simplify using the ‘XOR’ operator as given below. The code is concise, easier to understand, and the chances of introducing bugs is smaller than the previous version.