svn: /phpdoc/en/trunk/language/ operators.xml
| From: | Daniel Convissor | Date: | Thu, 27 Aug 2009 15:45:24 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ operators.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-4778@lists.php.net to get a copy of this message | ||
danielc Thu, 27 Aug 2009 15:45:24 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=287814
Log:
clarify precedence of logical operators, bug 48262
Bug: http://bugs.php.net/48262 (Assigned) Logical Operators
Manual Page Is Misleading
Changed paths:
U phpdoc/en/trunk/language/operators.xml
Modified: phpdoc/en/trunk/language/operators.xml
===================================================================
--- phpdoc/en/trunk/language/operators.xml 2009-08-27 14:45:41 UTC (rev 287813)
+++ phpdoc/en/trunk/language/operators.xml 2009-08-27 15:45:24 UTC (rev 287814)
@@ -1568,20 +1568,38 @@
<![CDATA[
<?php
+// --------------------
// foo() will never get called as those operators are short-circuit
+
$a = (false && foo());
$b = (true || foo());
$c = (false and foo());
$d = (true or foo());
+// --------------------
// "||" has a greater precedence than "or"
-$e = false || true; // $e will be assigned to (false || true) which is true
-$f = false or true; // $f will be assigned to false
+
+// The result of the expression (false || true) is assigned to $e
+// Acts like: ($e = (false || true))
+$e = false || true;
+
+// The constant false is assigned to $f and then true is ignored
+// Acts like: (($e = false) or true)
+$f = false or true;
+
var_dump($e, $f);
+// --------------------
// "&&" has a greater precedence than "and"
-$g = true && false; // $g will be assigned to (true && false) which is false
-$h = true and false; // $h will be assigned to true
+
+// The result of the expression (true && false) is assigned to $g
+// Acts like: ($g = (true && false))
+$g = true && false;
+
+// The constant true is assigned to $h and then false is ignored
+// Acts like: (($h = true) and false)
+$h = true and false;
+
var_dump($g, $h);
?>
]]>