PSR-2: Coding Style Guide (上)


網址:PSR-2: Coding Style Guide

General

 (1) Code MUST follow all rules outlined in PSR-1.
 (2) File:
   用Unix LF (linefeed)作為換行符號。
   單純PHP不用 ?> 結束,並以以一個空白行作為結束。
 (4)  Lines:建議在每行80個字左右,最多不要超過120個字。
 (5) Indenting:使用4個space,不要使用tab。(或將編輯器的tab鍵做修改)
 (6) Keywords and True/False/Null:PHP的keyword都用小寫

Namespace and Use Declarations

 namespace宣告與use之間空一行,use與class之間再空一行。
 There MUST be one use keyword per declaration.(?)

Classes, Properties, and Methods

 (1)Extends and Implements
  extends和implements關鍵字與其類別名稱必需被宣告在同一行。
  左右大括號{}都要自己獨立一行。
 
 (2)Properties:
  屬性在宣告時一定 (MUST) 要給予初始值,不可使用var來當屬性。
  不要使用底線作為前綴,來區分屬性是 protected 或 private。
 
 (3)Methods
  不要使用底線作為前綴,來區分方法是 protected 或 private。
  Method names後一定不能有空格,左右大括號{},前面不能有空格。

 (4)Method Arguments
  在參數中,每個逗號前不要有空白,而逗號後一定要有空白。

 (5)abstract, final, and static
  abstract與final必須加在visibility之前。static必須加在visibility之後。

 (6)Method and Function Calls
  Method and Function呼叫時,參數的左右括號()前後不能有空格。

沒有留言:

張貼留言