

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I was wondering if there are any disadvantages of using words (e.g. AND, OR) instead of their code equivalents (&&, ||) for comparison? Besides the later being a compatible syntax with many other programming languages, is there any other reason for choosing them?

share|improve this question
There is none... – Florent Oct 17 '12 at 8:30
up vote 6 down vote accepted

AND is not the same like &&

for example:

<?php $a && $b || $c; ?>

is not the same like

<?php $a AND $b || $c; ?>

the first thing is (a and b) or c

the second a and (b or c)

because || has got a higher priority than and, but less than &&

For more information check out PHP Logical Operators and Operator Precedence

share|improve this answer
I might be arguing semantics now, but imo they ARE the same (functionality wise). They do differ in precedence though. – Dennis Haarbrink Oct 17 '12 at 8:34

An unanticipated disadvantage comes when used with the = operator.

$result = false || true; # true, $result is true
/* Translated to result = (false || true) */


$result = false or true; # true, $result is false
/* Translated to (result = false) or true */
share|improve this answer
hakre, Thank you for the comment! – IndirectX Oct 17 '12 at 8:52

The PHP manual (in Logical Operators) talks about what you ask in your question:

The reason for the two different variations of "and" and "or" operators is that they operate at different precedences. (See Operator Precedence.)

So the difference is in the precedence, not the logical meaning of each single operator.

In your example: (x && y || z) and (x AND y OR z) you won't see any difference between the two expressions.

share|improve this answer

They do the same thing, but the && and || operators have higher precedence than AND and OR.

Basically I think this can become confusing so if you just stick to one notation and not mix them, you'll be fine and your code will remain readable.

share|improve this answer

Your Answer


