- Standard Header.
/*******************************************************************
* Filename:
* Copyright: © 2003-2004 CMSformE
* $Id$
*******************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*******************************************************************/
This header should be added to the beginning of every file. Be sure to fill in the file name in the correct place.
If the file is in any directories inside the root directory, be sure to include them in the format of: dir1/dir2/file.ext.
The header should have a blank line both above and below it.
If it is a PHP file, then the <?php can go above the blank line.
If it is an HTML or template file, abbreviate the header as <!--$Id$--> and put it on its own line, without any blank lines before it, and space the file as necessary.
If it is a plain text file, it MUST have a blank line before it, even if there isn't anything else there. This includes SQL files, which may have the header commented out differently to conform to the standards of that particular DBMS.
- Braces. All conditionals, loops, and function definitions MUST be enclosed in braces. This includes
if, elseif, else, while, for, foreach, switch, function, and class. Also, braces always get their own line.
Examples:
if( !( empty( $row['post_text_short'] ) ) && $mode != 'more' )
{
/* [...] */
}
elseif( $article && $mode == 'more' )
{
/* [...] */
}
else
{
/* [...] */
}
while( $row = $Database->fetch_assoc( $result ) )
{
/* [...] */
}
for( $i = 0; $i < $blockcount; $i++ )
{
/* [...] */
}
foreach( $row as $colname => $value )
{
/* [...] */
}
function sid()
{
/* [...] */
}
class Database
{
/* [...] */
}
- Spaces. All tokens and functions must be spaced properly. Variables should be separated from tokens by one space on each side. Functions should NOT have a space between the function name and the parentheses, but there should be one space on the inside of each parenthesis, except when there aren't any arguments inside or if casting a value. Arguments separated by commas (
,) should have one space after each comma (, ). There shouldn't be any spaces between the ending semicolon (;) and the code before it.
Examples:
define( 'ROOT', './' );
$news = array();
$post_limit = '';
$article = ( isset( $_GET['article'] ) ) ? (int) $_GET['article'] : '';
- Parentheses. Parentheses (
()) should always be used when there could be a question about hierarchy. Multiple comparisons on the same line should be separated from each other by parentheses, spaced accordingly. Parentheses should surround a negated statement, with the negation symbol (!) on the outside of the parentheses. This includes the negation of single functions and single variables. All functions, with the exception of print (which is actually a language construct), shall be followed immediately by an open parenthesis.
Examples:
$news = array();
define( 'ROOT', './' );
while( ( $file = @readdir( $dir ) ) !== FALSE )