## 代碼規范
### 遵循標準:
[php-fig標準](http://www.php-fig.org/psr/psr-4/)
[PHP編碼規范(中文版)](http://www.hmoore.net/thinkphp/php-fig-psr)
[REST API 安全設計指南](http://www.hmoore.net/kancloud/rest-api-design-safety)
[Web開發規范文檔](http://www.hmoore.net/chandler/css-code-guide)
[PHP之道(中文版)](http://www.hmoore.net/thinkphp/php-the-right-way)
[PHP 開發規范](http://www.hmoore.net/itsky71/php-standard)
[PHP設計模式簡介](http://larabase.com/collection/5/post/143)
[PHP 之道 | PHP The Right Way 中文版](http://laravel-china.github.io/php-the-right-way/)
[首頁 | TIPI: 深入理解PHP內核](http://php-internals.com/)
[Zephir Programming Language](https://zephir-lang.com/)
[CoffeePHP社區 - Powered by PHPHub](http://coffeephp.com/)
函數命名,類命名,文件名,目錄名等等
* 本項目代碼格式化標準選用 [**PSR-2**](http://www.hmoore.net/thinkphp/php-fig-psr/3141);
* 類名和類文件名遵循 [**PSR-4**](http://www.hmoore.net/thinkphp/php-fig-psr/3144);
* * * * *
### 關于Unix哲學
[關于Unix哲學](http://www.ruanyifeng.com/blog/2009/06/unix_philosophy.html)
>[danger] KEEP IT SIMPLE , STUPID ! (保持簡單,保持愚蠢。)
>[info] 一個程序只做一件事,并且做好,簡單即是最好。
* * * * *
### 編碼規范:
規定團隊設置編輯器為UTF-8(無BOM)編碼,否則團隊編碼不統一,使用github時出問題。或者難以管理,導致出現各種隱含的BUG。
使用空格縮進,tab為四個空格。參考:[sublime text3中tab怎么設置為默認縮進四個空格](https://zhidao.baidu.com/question/1672622739142258907.html)
最好有代碼審查工具。
注釋規范:
[“/\*\*/”與“/\*\*\*/”的區別](http://zhidao.baidu.com/link?url=qryCwVHuV5hMmvUSWS74iOmvrEcpdIxSSF6S6jJIv29qRyNdwXwFHQtjvf1mYBaBUETjrd5q4p4seWKC0IEUjq)
[javadoc自動生成開發文檔](http://blog.csdn.net/cxxxxc/article/details/4307116)
* * * * *
[4位神級大牛說“別神化程序員了,編程不需要天賦和激情!”_網易訂閱](http://dy.163.com/wemedia/article/detail/BQD2SG720511831M.html)
One man s crappy software is another man s full time job.(Jessica Gaston)
一個人寫的爛軟件將會給另一個人帶來一份全職工作。
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
傻瓜寫計算機能理解的代碼。優秀的程序員寫人類能讀懂的代碼。
Software and cathedrals are much the same — first we build them, then we pray.(Sam Redwine)
軟件和教堂非常相似——首先,我們建造它們,然后我們祈禱。(Sam Redwine)
* * * * *
### 開發環境
為了在開發環境中顯示所有可能的錯誤,將你的 php.ini 進行如下配置:
```ini
display_errors = On
display_startup_errors = On
error_reporting = -1
log_errors = On
```
* * * * *
### 生產環境
為了在生產環境中隱藏錯誤顯示,將你的 php.ini 進行如下配置:
```ini
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL
log_errors = On
```
[PHP之道 - 錯誤報告](http://www.hmoore.net/thinkphp/php-the-right-way/3192)
* * * * *
### 命名規范
函數/方法/變量 命名規范:動詞+名詞+形容詞
比如:addProducts()
* * * * *
### 返回碼規范
最好在一套系統中,甚至一個團隊,一個公司中都遵循一套返回狀態碼規則,并提前做好規劃,比如:
0001 ~ 1999 ,2000 ~ 2999,4000 ~ 4999
這些碼段可以按:業務類型,按功類型,按架構層面提前規劃好,比如x~y是網絡段的,哪段用于錯誤碼,哪段用于成功碼,感覺這樣從架構層面上來分比較清晰,一下子就知道是成功還是失敗了,然后根據其它位上的數還可以識別出業務層上面的特征,感覺這幾種規劃組合起來有最好的效果,給出碼段。這樣整體規劃就能達到統一了。
ABCD四位
A:?
B:?
C:?
D:?
last update:2017-10-11 01:03:03