note 15842 added to language.operators.logical
| From: | (spam.me.not.) | Date: | Thu, 04 Oct 2001 20:30:29 +0000 |
| Subject: | note 15842 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-18584@lists.php.net to get a copy of this message | ||
For those who might not pay close attention to matters of Operator Precedence, the manual is not
kidding when it says that "AND" and "&&" have different precedence. In
particular these two forms of logical operators straddle the assignment operator (=) in precedence!
For instance,
$a = $b && $c;
is not the same as
$a = $b AND $c;
The difference is that "AND" has lower precedence than the equals sign. To whit, the last
expression more closely resembles:
($a = $b) && $c
which probably isn't what you want.
This may be of aid to those who like their code to read like english, and might think that the
precedence differences of these operators are relatively exotic: they aren't.
As for me I ran into this problem because there is no symbolic logical XOR (for instance, no ^^) so
I had to use XOR, and then figured that in similar places I'd ought to use AND and OR, and then
my code broke :)
So now I've got to
$a = ($b xor $c);
Happy Trails
- - Jesse Thompson
bend.com
--
http://www.php.net/manual/en/language.operators.logical.php
http://master.php.net/manage/user-notes.php?action=edit+15842
http://master.php.net/manage/user-notes.php?action=delete+15842
http://master.php.net/manage/user-notes.php?action=reject+15842