note 106092 added to language.operators.assignment
| From: | ben at leftclick dot com dot au | Date: | Sun, 09 Oct 2011 15:45:35 +0000 |
| Subject: | note 106092 added to language.operators.assignment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183756@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 203.161.90.233
----
Manual Page -- http://www.php.net/manual/en/language.operators.assignment.php
Edit -- https://master.php.net/note/edit/106092
Del: integrated -- https://master.php.net/note/delete/106092/integrated
Del: useless -- https://master.php.net/note/delete/106092/useless
Del: bad code -- https://master.php.net/note/delete/106092/bad+code
Del: spam -- https://master.php.net/note/delete/106092/spam
Del: non-english -- https://master.php.net/note/delete/106092/non-english
Del: in docs -- https://master.php.net/note/delete/106092/in+docs
Del: other reasons-- https://master.php.net/note/delete/106092
Reject -- https://master.php.net/note/reject/106092
Search -- https://master.php.net/manage/user-notes.php