CVS update: php3/doc/chapters

From: Date: Tue, 25 May 1999 01:13:05 +0000
Subject: CVS update: php3/doc/chapters
Groups: php.dev 
Request: Send a blank email to php-dev+get-5964@lists.php.net to get a copy of this message
Date: Monday May 24, 1999 @ 21:13 Author: jim Update of /repository/php3/doc/chapters In directory php:/tmp/cvs-serv29125/chapters Modified Files: features.sgml lang-const.sgml lang-syntax.sgml Removed Files: lang-expr.sgml Log Message: Some initial manual shuffling. Finally moved 'Operators' section into the 'Language Constructs' chapter instead of one misnamed 'Expressions'. Fixed a couple of typos noticed along the way. (This appears to parse correctly, but I haven't waited to see what the output looks like since it takes 1/2 hour to generate on the machine I'm using. Someone should really profile that process some day and find out why it takes so damn long.) Index: php3/doc/chapters/features.sgml diff -u php3/doc/chapters/features.sgml:1.29 php3/doc/chapters/features.sgml:1.30 --- php3/doc/chapters/features.sgml:1.29 Sun May 16 19:14:25 1999 +++ php3/doc/chapters/features.sgml Mon May 24 21:13:05 1999 @@ -439,7 +439,7 @@ the <function>error_reporting</function> function. <simpara> - All <link linkend="lang-expr">PHP expressions</link> can also be called + All <link linkend="expressions">PHP expressions</link> can also be called with the "@" prefix, which turns off error reporting for that particular expression. If an error occurred during such an expression and the <link linkend="ini.track-errors">track_errors</link> feature Index: php3/doc/chapters/lang-const.sgml diff -u php3/doc/chapters/lang-const.sgml:1.38 php3/doc/chapters/lang-const.sgml:1.39 --- php3/doc/chapters/lang-const.sgml:1.38 Sat May 15 04:36:13 1999 +++ php3/doc/chapters/lang-const.sgml Mon May 24 21:13:05 1999 @@ -1285,7 +1285,7 @@ <para> Constructors are functions in a class that are automatically called when you create a new instance of a class. A function - becomes a constructur when it has the same name as the class. + becomes a constructor when it has the same name as the class. </para> <informalexample> @@ -1324,7 +1324,276 @@ </programlisting> </informalexample> + <para> + For derived classes, the constructor of the parent class is not + automatically called when the derived class's constructor is called. + </sect1> + + <sect1 id="operators"> + <title>Operators</title> + <simpara> + </simpara> + + <sect2 id="arithmetic-operators"> + <title>Arithmetic Operators</title> + <simpara> + Remember basic arithmetic from school? These work just + like those. + </simpara> + + <table> + <title>Arithmetic Operators</title> + <tgroup cols="3"> + <thead> + <row> + <entry>example</entry> + <entry>name</entry> + <entry>result</entry> + </row> + </thead> + <tbody> + <row> + <entry>$a + $b</entry> + <entry>Addition</entry> + <entry>Sum of $a and $b.</entry> + </row> + <row> + <entry>$a - $b</entry> + <entry>Subtraction</entry> + <entry>Remainder of $b subtracted from $a.</entry> + </row> + <row> + <entry>$a * $b</entry> + <entry>Multiplication</entry> + <entry>Product of $a and $b.</entry> + </row> + <row> + <entry>$a / $b</entry> + <entry>Division</entry> + <entry>Dividend of $a and $b.</entry> + </row> + <row> + <entry>$a % $b</entry> + <entry>Modulus</entry> + <entry>Remainder of $a divided by $b.</entry> + </row> + </tbody> + </tgroup> + </table> + +<!-- This appears to be inaccurate. Division always returns a float. + <simpara> + The division operator ("/") returns an integer value (the result + of an integer division) if the two operands are integers (or + strings that get converted to integers). If either operand is a + floating-point value, floating-point division is performed. + </simpara> +--> + + <sect2 id="string-operators"> + <title>String Operators</title> + <simpara> + There is only really one string operator -- the concatenation + operator ("."). + </simpara> + <para> + <informalexample><programlisting> +$a = "Hello "; +$b = $a . "World!"; // now $b = "Hello World!" + </programlisting></informalexample> + </para> + + <sect2 id="assignment-operators"> + <title>Assignment Operators</title> + <simpara> + The basic assignment operator is "=". Your first inclination might + be to think of this as "equal to". Don't. It really means that + the the left operand gets set to the value of the expression on the + rights (that is, "gets set to"). + </simpara> + <para> + The value of an assignment expression is the value assigned. That + is, the value of "$a = 3" is 3. This allows you to do some tricky + things: <informalexample><programlisting> +$a = ($b = 4) + 5; // $a is equal to 9 now, and $b has been set to 4. +</programlisting></informalexample> + </para> + <para> + In addition to the basic assignment operator, there are "combined + operators" for all of the binary arithmetic and string operators + that allow you to use a value in an expression and then set its + value to the result of that expression. For example: <informalexample><programlisting> +$a = 3; +$a += 5; // sets $a to 8, as if we had said: $a = $a + 5; +$b = "Hello "; +$b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!"; +</programlisting></informalexample> + </para> + + <sect2 id="bitwise-operators"> + <title>Bitwise Operators</title> + <simpara> + Bitwise operators allow you to turn specific bits within an integer + on or off. + </simpara> + + <table> + <title>Bitwise Operators</title> + <tgroup cols="3"> + <thead> + <row> + <entry>example</entry> + <entry>name</entry> + <entry>result</entry> + </row> + </thead> + <tbody> + <row> + <entry>$a & $b</entry> + <entry>And</entry> + <entry>Bits that are set in both $a and $b are set.</entry> + </row> + <row> + <entry>$a | $b</entry> + <entry>Or</entry> + <entry>Bits that are set in either $a or $b are set.</entry> + </row> + <row> + <entry>~ $a</entry> + <entry>Not</entry> + <entry>Bits that are set in $a are not set, and vice versa.</entry> + </row> + <row> + <entry>$a &lt;&lt; $b</entry> + <entry>Shift left</entry> + <entry>Shift the bits of $a $b steps to the left (each step means "multiply by two")</entry> + </row> + <row> + <entry>$a &gt;&gt; $b</entry> + <entry>Shift right</entry> + <entry>Shift the bits of $a $b steps to the right (each step means "divide by two")</entry> + </row> + </tbody> + </tgroup> + </table> + + <sect2 id="logical-operators"> + <title>Logical Operators</title> + + <table> + <title>Logical Operators</title> + <tgroup cols="3"> + <thead> + <row> + <entry>example</entry> + <entry>name</entry> + <entry>result</entry> + </row> + </thead> + <tbody> + <row> + <entry>$a and $b</entry> + <entry>And</entry> + <entry>True of both $a and $b are true.</entry> + </row> + <row> + <entry>$a or $b</entry> + <entry>Or</entry> + <entry>True if either $a or $b is true.</entry> + </row> + <row> + <entry>$a xor $b</entry> + <entry>Or</entry> + <entry>True if either $a or $b is true, but not both.</entry> + </row> + <row> + <entry>! $a</entry> + <entry>Not</entry> + <entry>True if $a is not true.</entry> + </row> + <row> + <entry>$a && $b</entry> + <entry>And</entry> + <entry>True of both $a and $b are true.</entry> + </row> + <row> + <entry>$a || $b</entry> + <entry>Or</entry> + <entry>True if either $a or $b is true.</entry> + </row> + </tbody> + </tgroup> + </table> + + <simpara> + The reason for the two different variations of "and" and "or" + operators is that they operate at different precedences. (See below.) + </simpara> + + <sect2 id="comparison-operators"> + <title>Comparison Operators</title> + <simpara> + Comparison operators, as their name imply, allow you to compare two + values. + </simpara> + + <table> + <title>Comparson Operators</title> + <tgroup cols="3"> + <thead> + <row> + <entry>example</entry> + <entry>name</entry> + <entry>result</entry> + </row> + </thead> + <tbody> + <row> + <entry>$a == $b</entry> + <entry>Equal</entry> + <entry>True if $a is equal to $b.</entry> + </row> + <row> + <entry>$a != $b</entry> + <entry>Not equal</entry> + <entry>True if $a is not equal to $b.</entry> + </row> + <row> + <entry>$a &lt; $b</entry> + <entry>Less than</entry> + <entry>True if $a is strictly less than $b.</entry> + </row> + <row> + <entry>$a &gt; $b</entry> + <entry>Greater than</entry> + <entry>True if $a is strictly greater than $b.</entry> + </row> + <row> + <entry>$a &lt;= $b</entry> + <entry>Less than or equal to </entry> + <entry>True if $a is less than or equal to $b.</entry> + </row> + <row> + <entry>$a &gt;= $b</entry> + <entry>Greater than or equal to </entry> + <entry>True if $a is greater than or equal to $b.</entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + Another conditional operator is the "?:" (or trinary) operator, which + operates as in C and many other languages. + <informalexample><programlisting>(expr1) ? (expr2) : (expr3);</programlisting></informalexample> + This expression returns to <symbol>expr2</symbol> if + <symbol>expr1</symbol> evalutes to true, and expr3 if + <symbol>expr1</symbol> evaluates to false. + + <sect2 id="precedence"> + <title>Precedence</title> + <simpara></simpara> <!-- Keep this comment at the end of the file Local variables: Index: php3/doc/chapters/lang-syntax.sgml diff -u php3/doc/chapters/lang-syntax.sgml:1.38 php3/doc/chapters/lang-syntax.sgml:1.39 --- php3/doc/chapters/lang-syntax.sgml:1.38 Sun May 23 21:22:44 1999 +++ php3/doc/chapters/lang-syntax.sgml Mon May 24 21:13:05 1999 @@ -51,38 +51,42 @@ </informalexample> <sect1 id="comment-syntax"> - <title>Commenting Code</title> + <title>Commenting code</title> <para> - PHP supports 'C', 'C++' and Unix shell-style comments. For example: + PHP supports 'C', 'C++' and Unix shell-style comments. For example: - <informalexample> - <programlisting> + <informalexample><programlisting> &lt;?php echo "This is a test"; // This is a one-line c++ style comment /* This is a multi line comment yet another line of comment */ echo "This is yet another test"; echo "One Final Test"; # This is shell-style style comment - ?> </programlisting> </informalexample> + <simpara> - You should be careful not to embed 'C' style comments, which can happen when commenting - out large blocks, as this will cause problems: + The "one-line" comment styles actually only comment to the + end of the line or the current block of PHP code, whichever + comes first. + <informalexample><programlisting> +&lt;h1>This is an &lt;?# echo "simple";?> example.&lt;/h1> +&lt;p>The header above will says 'This is an example'. +</programlisting></informalexample> - <informalexample> - <programlisting> + <simpara> + You should be careful not to nest 'C' style comments, which can + happen when commenting out large blocks. + + <informalexample><programlisting> &lt;?php /* echo "This is a test"; /* This comment will cause a problem */ - */ ?> - </programlisting> - </informalexample> - + </programlisting></informalexample> <sect1 id="variable-types"> <title>Variable types</title> @@ -665,20 +669,6 @@ <simpara> For more information on this conversion, see the Unix manual page for strtod(3). - - <sect1 id="string-concatination"> - <title>String concatination</title> - <para> - PHP follows the Perl method for joining two strings together by - using the dot '.' operator. - <informalexample> - <programlisting> -$oldstring = "abcdef"; -$newstring = "&lt;br>" . $oldstring . "&lt;br>" /* result: "&lt;br>abcdef&lt;br>" */ - </programlisting> - </informalexample> - - </sect1> <sect1 id="variable-arrays"> <title>Array manipulation</title> -- 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 (#5964) next »