svn: /phpdoc/en/trunk/language/ operators.xml
| From: | Mike Ford | Date: | Thu, 09 Jun 2011 07:20:56 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/ operators.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-8226@lists.php.net to get a copy of this message | ||
mgf Thu, 09 Jun 2011 07:20:56 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=311960
Log:
Rewrite of Operators intro and tidy up of text around Precedence table.
Changed paths:
U phpdoc/en/trunk/language/operators.xml
Modified: phpdoc/en/trunk/language/operators.xml
===================================================================
--- phpdoc/en/trunk/language/operators.xml 2011-06-09 07:16:13 UTC (rev 311959)
+++ phpdoc/en/trunk/language/operators.xml 2011-06-09 07:20:56 UTC (rev 311960)
@@ -3,25 +3,26 @@
<chapter xml:id="language.operators" xmlns="http://docbook.org/ns/docbook">
<title>Operators</title>
<simpara>
- An operator is something that you feed with one or more values (or
- expressions, in programming jargon) which yields another value (so that the
- construction itself becomes an expression). So you can think of functions
- or constructions that return a value (like print) as operators and those
- that return nothing (like echo) as any other thing.
+ An operator is something that takes one or more values (or
+ expressions, in programming jargon) and yields another value (so that the
+ construction itself becomes an expression).
</simpara>
<para>
- There are three types of operators. Firstly there is the unary operator which
- operates on only one value, for example ! (the negation operator) or ++
- (the increment operator). The second group are termed binary operators; this
- group contains most of the operators that PHP supports, and a list follows
- below in the section <link linkend="language.operators.precedence">Operator
- Precedence</link>.
+ Operators can be grouped according to the number of values they take. Unary
+ operators take only one value, for example ! (the negation operator) or ++
+ (the increment operator). Binary operators take two values, such as the
+ familiar arithmetical + (plus) and - (minus), and the majority of PHP
+ operators fall into this category. Finally there is a single ternary
+ operator, ? :, which takes three values; this is usually referred to simply
+ as "the ternary operator" (although it should more properly be called the
+ conditional operator).
</para>
<para>
- The third group is the ternary operator: ?:. It should be used to select
- between two expressions depending on a third one, rather than to select two
- sentences or paths of execution. Surrounding ternary expressions with
- parentheses is a very good idea.
+ A full list of PHP operators follows in the section
+ <link linkend="language.operators.precedence">Operator Precedence</link>.
+ This also explains operator Presedence and Associativity, which govern
+ exactly how expressions containing several different operators are
+ evaluated.
</para>
<sect1 xml:id="language.operators.precedence">
@@ -34,14 +35,18 @@
has a higher precedence than the addition ("+") operator.
Parentheses may be used to force precedence, if necessary. For
instance: <literal>(1 + 5) * 3</literal> evaluates to
- <literal>18</literal>. If operator precedence is equal, left to right
- associativity is used.
+ <literal>18</literal>.
</para>
<para>
- The following table lists the precedence of operators with the
- highest-precedence operators listed at the top of the table. Operators
- on the same line have equal precedence, in which case their
- associativity decides which order to evaluate them in.
+ When operators have equal precedence, their associativity decides
+ whether they are evaluated starting from the right, or starting from
+ the left - see the examples below.
+ </para>
+ <para>
+ The following table lists the operators in order of precedence, with
+ the highest-precedence ones at the top. Operators on the same line
+ have equal precedence, in which case associativity decides the order
+ of evaluation.
<table>
<title>Operator Precedence</title>
<tgroup cols="2">
@@ -208,8 +213,9 @@
</table>
</para>
<para>
- Left associativity means that the expression is evaluated from left to right,
- right associativity means the opposite.
+ For operators of equal precedence, left associativity means that
+ evaluation proceeds from left to right, and right associativity means
+ the opposite.
<example>
<title>Associativity</title>
<programlisting role="php">
@@ -229,7 +235,8 @@
]]>
</programlisting>
</example>
- Use parentheses to increase readability of the code.
+ Use of parentheses, even when not strictly necessary, can often increase
+ readability of the code.
</para>
<note>
<para>