svn: /phpdoc/en/trunk/language/ operators.xml
| From: | Christoph Michael Becker | Date: | Thu, 07 Jul 2016 18:41:06 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ operators.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-14291@lists.php.net to get a copy of this message | ||
cmb Thu, 07 Jul 2016 18:41:06 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=339582
Log:
Add example wrt. +,- and . having the same precedence
Albeit the behavior should be clear from the precendence table, Antistone
posted a note about this two years ago which has got 67 votes and there
have been two replies to this note which also have been upvoted, so we
integrate this information into the manual, and delete the notes.
Changed paths:
U phpdoc/en/trunk/language/operators.xml
Modified: phpdoc/en/trunk/language/operators.xml
===================================================================
--- phpdoc/en/trunk/language/operators.xml 2016-07-07 14:34:19 UTC (rev 339581)
+++ phpdoc/en/trunk/language/operators.xml 2016-07-07 18:41:06 UTC (rev 339582)
@@ -319,6 +319,30 @@
]]>
</programlisting>
</example>
+ <example>
+ <title><literal>+</literal>, <literal>-</literal> and
<literal>.</literal> have the same precedence</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$x = 4;
+// this line might result in unexpected output:
+echo "x minus one equals " . $x-1 . ", or so I hope\n";
+// because it is evaluated like this line:
+echo (("x minus one equals " . $x) - 1) . ", or so I hope\n";
+// the desired precendence can be enforced by using parentheses:
+echo "x minus one equals " . ($x-1) . ", or so I hope\n";
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+-1, or so I hope
+-1, or so I hope
+x minus one equals 3, or so I hope
+]]>
+ </screen>
+ </example>
</para>
<note>
<para>