Coding Standards: Syntax and identation

From: Date: Sat, 02 Dec 2000 20:48:36 +0000
Subject: Coding Standards: Syntax and identation
Groups: php.pear 
Request: Send a blank email to php-pear+get-469@lists.php.net to get a copy of this message
Hi, does PEAR overtake the PHP Coding Standards when it comes to syntax and identation? PHP 4 CODING_STANDARDS: < Syntax and indentation < ---------------------- < < [1] Never use C++ style comments (i.e. // comment). Always use C-style < comments instead. PHP is written in C, and is aimed at compiling... That means I should use this style, right? /* one line comment */ /* multi line comment */ < [2] Use K&R-style. Of course, we can't and don't want to < force anybody to use a style he or she is not used to, but, < at the very least, when you write code that goes into the core < of PHP or one of its standard modules, please maintain the K&R < style. This applies to just about everything, starting with < indentation and comment styles and up to function decleration < syntax. Is that a must if it comes to curly braces? I preferr the BSD style instead of the K&R one. This is K&R: function foo($param) { if ( "" != $param ) print "\$param is no an empty string."; else { print "\$param"; print " is an empty string."; } } This is what I preferr: function foo($param) { ... } < [3] Be generous with whitespace and braces. Always prefer: < < if (foo) { < bar; < } < < to: < < if(foo)bar; Hmm, what about: if ($foo) bar(); < Keep one empty line between the variable decleration section and Is there any rule on this for PHP code. < the statements in a block, as well as between logical statement How about operators. Do I have to insert spaces around an operator such as: print $bar + $foo; < groups in a block. Maintain at least one empty line between < two functions, preferably two. < <[4] When indenting, use the tab character. A tab is expected to represent < four spaces. It is important to maintain consistency in indenture so < that definitions, comments, and control structures line up correctly. I used tabs with a width of 2 spaces in PHPDoc, was that a good idea? Ulf

« previous php.pear (#469) next »