and
and or
have higher lower precedence than &&
and ||
. To be more exact &&
and ||
have higher precedence than assignment operator ( =
) while and
and or
have lower.
http://www.php.net/manual/en/language.operators.precedence.php
Usually it doesn't make a difference, but there are cases when not knowing about this difference can cause some unexpected behaviour. See examples here:
http://php.net/manual/en/language.operators.logical.php
EDIT(suggested by @towr):
Applied to the question at hand, this means that in the first case we assign to $conn
the value mysql_connect(....) || die('....'),
because ||
has a higher precendence than =
. The problem here is that $conn
now is a boolean, and not a resource.
In the second case we OR
the expressions $conn = mysql_connect(....)
and die('....'),
because =
has a higher precendence than OR
. We do nothing with the boolean value, and $conn
is simply the resource we assigned to it in the first expression (if it didn't fail).