catalog
Typecho PHP encoding specification
appointment
Document code
indent
UNIX encoding specification
<? php //this is a test file echo 'hello' ; <--- Leave this line blank
UNIX Style Wrap
name
File Naming
Class Naming
class Typecho_Db {
Function (method, interface) naming
public function fetchRows ( Typecho_Db_Query $query , array $filter = NULL )
Variable Naming
protected $callbackFunctions ;
private $_adapter ;
Constant Names
define ( '__TYPECHO_DB_ADAPTER__' , 'Mysql' ) ;
notes
header comment
<? php /** * Typecho Blog Platform * * @author qining * @copyright Copyright (c) 2008 Typecho team ( http://www.typecho.org ) * @license GNU General Public License 2.0 * @version $Id$ */
Reference files and defining constant comments
/**Define Database Adapter**/ define ( '__TYPECHO_DB_ADAPTER__' , 'Mysql' ) ; /**Database exception**/ require_once 'Db/Exception.php' ;
/** *Define database query read/write status *True indicates the read status *False indicates the write status * */ define ( '__TYPECHO_DB_READ__' , true ) ; define ( '__TYPECHO_DB_WRITE__' , false ) ;
Class (interface) comments
/** *Class containing support methods for obtaining data *__TYPECHO_DB_HOST__, __TYPECHO_DB_PORT__, __TYPECHO_DB_NAME__ must be defined, * __TYPECHO_DB_USER__, __TYPECHO_DB_PASS__, __TYPECHO_DB_CHAR__ * * @package Db */ class Typecho_Db {
Function (method, interface) comments
/** *Get all rows at once * *@ param TypechoDbQuery $query Query object *@ param array $filter row filter function, which takes each query row as the first parameter and passes it into the specified filter * @return array */ public function fetchRows ( Typecho_Db_Query $query , array $filter = NULL ) { /** *Database class constructor * *@ param string $adapter Database adapter name * @return void * @throws TypechoDbException */ public function __construct ( $adapter = __TYPECHO_DB_ADAPTER__ ) {
Program interline comment
//Instantiate adapter object $this -> _adapter = new $adapter ( ) ;
Brace Placement
class TypechoDb { public function __construct ( $adapter = __TYPECHO_DB_ADAPTER__ ) { if ( ! defined ( $const = '__TYPECHO_DB_HOST__' ) || ! defined ( $const = '__TYPECHO_DB_PORT__' ) || ! defined ( $const = '__TYPECHO_DB_NAME__' ) || ! defined ( $const = '__TYPECHO_DB_USER__' ) || ! defined ( $const = '__TYPECHO_DB_PASS__' ) || ! defined ( $const = '__TYPECHO_DB_CHAR__' ) ) { } else { }
Comma placement
public function connect ( $host , $port , $db , $user , $password , $charset = NULL )
Space Use
$host . ':' . $port
Code layout
Class layout
__construct private protected public __destruct
private protected public
Blank line usage