第 4 章. 编码规范

本章内容
代码缩进和行长度
控制结构
函数的调用
函数的定义
代码注释
包含(引用)代码
PHP 代码标签
头部注释
使用 CVS
Example URLs
命名规范
文件格式
一个例子

注意: 官方分发的 PEAR代码将严格执行PEAR 编码规范.(包括以代码形式分发或在PEAR代码库中提供下载的代码)。

代码缩进和行长度

PEAR 采用 4 个空格来缩排代码,并且不使用Tab制表符。如果您正在使用 Emacs 编辑器来写 PEAR 代码,请把自动Tab缩进(indent-tabs-mode)设置为零。Here is an example mode hook that will set up Emacs according to these guidelines (you will need to ensure that it is called when you are editing PHP files):
(defun php-mode-hook ()
  (setq tab-width 4
        c-basic-offset 4
        c-hanging-comment-ender-p nil
        indent-tabs-mode
  (not
    (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
      (string-match "\.php$" (buffer-file-name))))))

如果使用VIM,将下列设置写入你的~/.vimrc中:
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4

我们建议您大约每 75-78 个字符就换一行。这并没有硬性的标准,您可以根据自己的尺度来做,或者到质量保证邮件列表上去询问。