philip Tue Jun 17 23:11:25 2003 EDT Modified files: /phpdoc/en/language expressions.xml Log: Remove use of <emphasis> tag in CDATA as per Jin Tae-Young's suggestion, and Whitespace. Index: phpdoc/en/language/expressions.xml diff -u phpdoc/en/language/expressions.xml:1.20 phpdoc/en/language/expressions.xml:1.21 --- phpdoc/en/language/expressions.xml:1.20 Mon Jun 9 15:28:28 2003 +++ phpdoc/en/language/expressions.xml Tue Jun 17 23:11:25 2003 @@ -1,31 +1,29 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.20 $ --> +<!-- $Revision: 1.21 $ --> <chapter id="language.expressions"> <title>Expressions</title> - <simpara> Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a - value".</simpara> - + value". + </simpara> <simpara> The most basic forms of expressions are constants and variables. When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression with the - value of 5 (in this case, '5' is an integer constant).</simpara> - + value of 5 (in this case, '5' is an integer constant). + </simpara> <simpara> After this assignment, you'd expect $a's value to be 5 as well, so if you wrote $b = $a, you'd expect it to behave just as if you wrote $b = 5. In other words, $a is an expression with the value of 5 as well. If everything works right, this is exactly - what will happen.</simpara> - + what will happen. + </simpara> <para> Slightly more complex examples for expressions are functions. For instance, consider the following function: - <informalexample> <programlisting role="php"> <![CDATA[ @@ -37,8 +35,8 @@ ?> ]]> </programlisting> - </informalexample></para> - + </informalexample> + </para> <simpara> Assuming you're familiar with the concept of functions (if you're not, take a look at the chapter about functions), you'd assume @@ -46,8 +44,8 @@ writing <literal>$c = 5</literal>, and you're right. Functions are expressions with the value of their return value. Since foo() returns 5, the value of the expression 'foo()' is 5. Usually - functions don't just return a static value but compute something.</simpara> - + functions don't just return a static value but compute something. + </simpara> <simpara> Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports three scalar value types: integer values, @@ -55,8 +53,8 @@ you can't 'break' into smaller pieces, unlike arrays, for instance). PHP also supports two composite (non-scalar) types: arrays and objects. Each of these value types can be assigned into variables or - returned from functions.</simpara> - + returned from functions. + </simpara> <simpara> So far, users of PHP/FI 2 shouldn't feel any change. However, PHP takes expressions much further, in the same way many other @@ -72,8 +70,8 @@ is an expression with the value 5. Thus, writing something like '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a - right to left order, you can also write '$b = $a = 5'.</simpara> - + right to left order, you can also write '$b = $a = 5'. + </simpara> <simpara> Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP/FI 2 and many other @@ -92,8 +90,8 @@ value, thus the name 'pre-increment'). Post-increment, which is written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable - after reading its value, thus the name 'post-increment').</simpara> - + after reading its value, thus the name 'post-increment'). + </simpara> <simpara> A very common type of expressions are comparison expressions. These expressions evaluate to either 0 or 1, meaning &false; or &true; @@ -101,8 +99,8 @@ or equal to), == (equal), != (not equal), < (smaller than) and <= (smaller than or equal to). These expressions are most commonly used inside conditional execution, such as <literal>if</literal> - statements.</simpara> - + statements. + </simpara> <simpara> The last example of expressions we'll deal with here is combined operator-assignment expressions. You already know that if you @@ -125,29 +123,32 @@ operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of $a), '$b *= 7' (multiply the value of $b by 7), etc. </simpara> - <para> There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator: - - <informalexample><programlisting> + </para> + <para> + <informalexample> + <programlisting> <![CDATA[ <?php $first ? $second : $third ?> ]]> - </programlisting></informalexample> - + </programlisting> + </informalexample> + </para> + <para> If the value of the first subexpression is &true; (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value. </para> - <para> The following example should help you understand pre- and post-increment and expressions in general a bit better: - + </para> + <para> <informalexample> <programlisting role="php"> <![CDATA[ @@ -164,9 +165,9 @@ /* at this point, both $d and $e are equal to 6 */ -$f = double($d++); /* assign twice the value of $d <emphasis>before</emphasis> +$f = double($d++); /* assign twice the value of $d before the increment, 2*6 = 12 to $f */ -$g = double(++$e); /* assign twice the value of $e <emphasis>after</emphasis> +$g = double(++$e); /* assign twice the value of $e after the increment, 2*7 = 14 to $g */ $h = $g += 10; /* first, $g is incremented by 10 and ends with the value of 24. the value of the assignment (24) is @@ -177,7 +178,6 @@ </programlisting> </informalexample> </para> - <simpara> In the beginning of the chapter we said that we'll be describing the various statement types, and as promised, expressions can be @@ -185,8 +185,8 @@ this case, a statement has the form of 'expr' ';' that is, an expression followed by a semicolon. In '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself. '$b=$a=5;' - however is a valid statement.</simpara> - + however is a valid statement. + </simpara> <simpara> One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're @@ -208,8 +208,8 @@ above examples should give you a good idea about what expressions are and how you can construct useful expressions. Throughout the rest of this manual we'll write <replaceable>expr</replaceable> - to indicate any valid PHP expression.</simpara> - + to indicate any valid PHP expression. + </simpara> </chapter> <!-- Keep this comment at the end of the file
-- PHP Documentation Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php