note 106092 deleted from language.operators.assignment by danbrown

From: Date: Mon, 10 Oct 2011 15:46:33 +0000
Subject: note 106092 deleted from language.operators.assignment by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183769@lists.php.net to get a copy of this message
Note Submitter: ben at leftclick dot com dot au ---- In response to user inca below, the &= operator is a bitwise operator, not a logical operator. Lazy evaluation applies only to logical operations. To clarify, the following two lines of code are equivalent. Both always call bar(), and both always assign a numeric value to $foo: $foo &= bar(); $foo = $foo & bar(); The following line of code is different from the the above two. It only calls bar() if $foo is (converted to) true, and always assigns a boolean value (true or false) to $foo: $foo = $foo && bar(); This will make a difference if you use the identical comparison operators: if ($foo === true) { // This will never be the case if you assigned the result of & or &= to $foo } if ($foo === 1) { // This will never be the case if you assigned the result of && to $foo } The same rules apply to the |=, | and || operators.

« previous php.notes (#183769) next »