CVS update: php3/doc/chapters

From: Date: Tue, 08 Dec 1998 03:11:11 +0000
Subject: CVS update: php3/doc/chapters
Groups: php.dev 
Request: Send a blank email to php-dev+get-2712@lists.php.net to get a copy of this message
Date: Monday December 7, 1998 @ 22:11 Author: jim Update of /repository/php3/doc/chapters In directory asf:/u/temp/cvs-serv13835/chapters Modified Files: lang-const.sgml Log Message: Add notes from errata. Index: php3/doc/chapters/lang-const.sgml diff -c php3/doc/chapters/lang-const.sgml:1.27 php3/doc/chapters/lang-const.sgml:1.28 *** php3/doc/chapters/lang-const.sgml:1.27 Sat Nov 28 01:44:42 1998 --- php3/doc/chapters/lang-const.sgml Mon Dec 7 22:11:11 1998 *************** *** 62,69 **** <simpara> So far, users of PHP/FI 2 shouldn't feel any change. However, PHP ! 3 takes expressions much further, in the same way many other ! languages do. PHP 3 is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer --- 62,69 ---- <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 ! languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer *************** *** 84,91 **** variable--. These are increment and decrement operators. In PHP/FI 2, the statement '$a++' has no value (is not an expression), and thus you can't assign it or use it in any way. ! PHP 3 enhances the increment/decrement capabilities by making ! these expressions as well, like in C. In PHP 3, like in C, there are two types of increment - pre-increment and post-increment. Both pre-increment and post-increment essentially increment the variable, and the effect on the variable is idential. The --- 84,91 ---- variable--. These are increment and decrement operators. In PHP/FI 2, the statement '$a++' has no value (is not an expression), and thus you can't assign it or use it in any way. ! PHP enhances the increment/decrement capabilities by making ! these expressions as well, like in C. In PHP, like in C, there are two types of increment - pre-increment and post-increment. Both pre-increment and post-increment essentially increment the variable, and the effect on the variable is idential. The *************** *** 114,120 **** very efficient or comfortable way. A much more common practice is to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a plus 3, and is assigned back into $a, which results in ! incrementing $a by 3. In PHP 3, as in several other languages like C, you can write this in a shorter way, which with time would become clearer and quicker to understand as well. Adding 3 to the current value of $a can be written '$a += 3'. This means exactly --- 114,120 ---- very efficient or comfortable way. A much more common practice is to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a plus 3, and is assigned back into $a, which results in ! incrementing $a by 3. In PHP, as in several other languages like C, you can write this in a shorter way, which with time would become clearer and quicker to understand as well. Adding 3 to the current value of $a can be written '$a += 3'. This means exactly *************** *** 128,133 **** --- 128,144 ---- the value of $a), '$b *= 7' (multiply the value of $b by 7), etc. <para> + There is one more expression that may seem odd if you haven't + seen it in other languages, the terniary conditional operator: + <informalexample><programlisting> + $first ? $second : $third + </programlisting></informalexample> + If the value of the first subexpression is true (non-zero), then + it 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> The following example should help you understand pre- and post-increment and expressions in general a bit better: <informalexample> *************** *** 169,179 **** contains no elements it's considered FALSE, otherwise it's considered TRUE. <simpara> ! PHP 3 provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The 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 'expr' to mark any valid PHP3 expression. <sect1 id="construct.if"> --- 180,190 ---- contains no elements it's considered FALSE, otherwise it's considered TRUE. <simpara> ! PHP provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The 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 'expr' to indicate any valid PHP3 expression. <sect1 id="construct.if"> *************** *** 464,479 **** print $i; $i++; } </programlisting></informalexample> <simpara> ! Of course, the first example appears to be the nicest one, but you ! may find that being able to use empty expressions in FOR loops comes ! in handy in many occasions. ! <para>There is only one format for FOR loops in PHP 3. ! <informalexample><programlisting> ! FOR(expr): ... ENDFOR; is NOT supported. </programlisting></informalexample> <para> --- 475,495 ---- print $i; $i++; } + + /* example 4 */ + for ($i=1; $i<=10; print $i, $i++) ; + </programlisting></informalexample> <simpara> ! Of course, the first example appears to be the nicest one (or perhaps ! the fourth), but you may find that being able to use empty expressions ! in FOR loops comes in handy in many occasions. ! <para> ! PHP also supports the alternate "colon syntax" for FOR loops. ! <informalexample><programlisting> ! FOR (expr1; expr2; expr3): statement; ...; endfor; </programlisting></informalexample> <para> *************** *** 626,631 **** --- 642,650 ---- Any valid PHP3 code may appear inside a function, even other functions and <link linkend="keyword.class">class</link> definitions. + <simpara> + Functions must be defined before they are referenced. + <sect2 id="keyword.function.return"> <title>Returning values</title> <para> *************** *** 663,672 **** <para> PHP3 supports passing arguments by value (the default), <link linkend="keyword.function.arguments.reference">passing by ! reference</link>, and <link ! linkend="keyword.function.arguments.default">default argument ! values</link>. Variable-length argument lists are not supported, but a similar effect may be achieved by passing arrays. <sect3 id="keyword.function.arguments.reference"> <title>Passing by reference</title> --- 682,695 ---- <para> PHP3 supports passing arguments by value (the default), <link linkend="keyword.function.arguments.reference">passing by ! reference</link>, and <link linkend="keyword.function.arguments.default">default argument ! values</link>. Variable-length argument lists are not supported, but a similar effect may be achieved by passing arrays. + <informalexample><programlisting> + function takes_array($input) { + echo "$input[0] + $input[1] = ", $input[0]+$input[1]; + } + </programlisting></informalexample> <sect3 id="keyword.function.arguments.reference"> <title>Passing by reference</title> *************** *** 730,735 **** --- 753,762 ---- Making a cup of cappucino. Making a cup of espresso. </screen> + + <simpara> + The default value must be a constant expression, not (for + example) a variable or class member. <para> Note that when using default arguments, any defaults should be on -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#2712) next »