note 15842 deleted from language.operators.logical by colder

From: Date: Tue, 01 May 2007 05:44:41 +0000
Subject: note 15842 deleted from language.operators.logical by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126009@lists.php.net to get a copy of this message
Note Submitter: jesse at bend dot (spam dot me dot not dot )com ---- 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

« previous php.notes (#126009) next »