帳號登錄
帳號:
密碼:
記住我 | 忘記密碼 | 帳號註冊
網站導覽
模組開發 : PEAR 程式撰寫標準-函式定義
作者 elie 於 2010年08月15日 15:20:00 (3816 次閱讀)

原始出處 http://www.xoops.org/modules/mediawiki/index.php/Dev:coding_standards

 

函式宣告遵守"一個真正的大括弧"約定:


function fooFunction($arg1, $arg2 = '')
{
    if (condition) {
        statement;
    }
    return $val;
}
?>

有預設值的參數要在參數列的最後面。要讓函式回傳有意義的值。接下來是另外一個範例:


function connect(&$dsn, $persistent = false)
{
    if (is_array($dsn)) {
        $dsninfo = &$dsn;
    } else {
        $dsninfo = DB::parseDSN($dsn);
    }
 
    if (!$dsninfo || !$dsninfo['phptype']) {
        return $this->raiseError();
    }
 
    return true;
}
?>


可列印模式 轉寄給朋友

The XOOPS organisation ("XOOPS") is committed to protecting the privacy of users of the XOOPS.org sites.
The website used Ver.2.4.5 POWERED BY XOOPS PROJECT.