cvs: peardoc /en/chapters standards.xml

From: Date: Wed, 12 May 2004 22:27:59 +0000
Subject: cvs: peardoc /en/chapters standards.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-3966@lists.php.net to get a copy of this message
danielc Wed May 12 18:27:59 2004 EDT Modified files: /peardoc/en/chapters standards.xml Log: Put CDATA in most programlisting's. http://cvs.php.net/diff.php/peardoc/en/chapters/standards.xml?r1=1.18&r2=1.19&ty=u Index: peardoc/en/chapters/standards.xml diff -u peardoc/en/chapters/standards.xml:1.18 peardoc/en/chapters/standards.xml:1.19 --- peardoc/en/chapters/standards.xml:1.18 Wed May 12 18:23:12 2004 +++ peardoc/en/chapters/standards.xml Wed May 12 18:27:58 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.18 $ --> +<!-- $Revision: 1.19 $ --> <chapter id="standards"> <title>Coding Standards</title> @@ -18,6 +18,7 @@ hook that will set up Emacs according to these guidelines (you will need to ensure that it is called when you are editing PHP files): <programlisting role="elisp"> + <![CDATA[ (defun php-mode-hook () (setq tab-width 4 c-basic-offset 4 @@ -26,15 +27,18 @@ (not (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name)) (string-match "\.php$" (buffer-file-name)))))) -</programlisting> + ]]> + </programlisting> </para> <para>Here are vim rules for the same thing: <programlisting role="vim"> - set expandtab - set shiftwidth=4 - set softtabstop=4 - set tabstop=4 -</programlisting> + <![CDATA[ +set expandtab +set shiftwidth=4 +set softtabstop=4 +set tabstop=4 + ]]> + </programlisting> </para> <para> It is recommended that you break lines at approximately 75-85 characters. @@ -51,14 +55,16 @@ These include if, for, while, switch, etc. Here is an example if statement, since it is the most complicated of them: <programlisting role="php"> + <![CDATA[ if ((condition1) || (condition2)) { action1; -} elseif ((condition3) &amp;&amp; (condition4)) { +} elseif ((condition3) && (condition4)) { action2; } else { defaultaction; } -</programlisting> + ]]> + </programlisting> </para> <simpara> Control statements should have one space between the control keyword @@ -72,7 +78,8 @@ </simpara> <para> For switch statements: - <programlisting role="php"> + <programlisting role="php"> + <![CDATA[ switch (condition) { case 1: action1; @@ -85,9 +92,9 @@ default: defaultaction; break; - } -</programlisting> + ]]> + </programlisting> </para> </sect1> @@ -100,8 +107,10 @@ parameter, the closing parenthesis, and the semicolon. Here's an example: <programlisting role="php"> + <![CDATA[ $var = foo($bar, $baz, $quux); -</programlisting> + ]]> + </programlisting> </para> <para> As displayed above, there should be one space on either side of an @@ -109,9 +118,11 @@ variable. In the case of a block of related assignments, more space may be inserted to promote readability: <programlisting role="php"> + <![CDATA[ $short = foo($bar); $long_variable = foo($baz); -</programlisting> + ]]> + </programlisting> </para> </sect1> @@ -121,6 +132,7 @@ Function declarations follow the <quote>one true brace</quote> convention: <programlisting role="php"> + <![CDATA[ function fooFunction($arg1, $arg2 = '') { if (condition) { @@ -128,17 +140,19 @@ } return $val; } -</programlisting> + ]]> + </programlisting> </para> <para> Arguments with default values go at the end of the argument list. Always attempt to return a meaningful value from a function if one is appropriate. Here is a slightly longer example: <programlisting role="php"> -function connect(&amp;$dsn, $persistent = false) + <![CDATA[ +function connect(&$dsn, $persistent = false) { if (is_array($dsn)) { - $dsninfo = &amp;$dsn; + $dsninfo = &$dsn; } else { $dsninfo = DB::parseDSN($dsn); } @@ -149,6 +163,7 @@ return true; } + ]]> </programlisting> </para> </sect1> @@ -500,7 +515,7 @@ // | Your Name <you@example.com> | // +----------------------------------------------------------------------+ // -// $Id: standards.xml,v 1.18 2004/05/12 22:23:12 danielc Exp $ +// $Id: standards.xml,v 1.19 2004/05/12 22:27:58 danielc Exp $ require_once 'PEAR.php'; @@ -552,7 +567,7 @@ * @category categoryname * @package packagename * @author Original Author <author@example.com> - * @version $Id: standards.xml,v 1.18 2004/05/12 22:23:12 danielc Exp $ + * @version $Id: standards.xml,v 1.19 2004/05/12 22:27:58 danielc Exp $ * @access public * @see NetOther, Net_Sample::Net_Sample() * @since Class available since Release 1.2.0

« previous php.pear.doc (#3966) next »