PHP 编码规范

1.Code MUST use 4 spaces for indenting, not tabs.代码必须用4个空格缩进,而不是用tab

2.There MUST be one blank line after the namespace declaration, and there MUST be one blank line after the block of use declarations.

在namespace 和 use 后面要有空行

3.Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body

4.Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.

5.Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility.

6.Control structure keywords MUST have one space after them; method and function calls MUST NOT.

7.Opening braces for control structures MUST go on the same line, and closing braces MUST go on the next line after the body.

8.Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.

 控制结构的开括号后面没有空格,闭括号前面没有空格

 

<?php
namespace Vendor\Package;

use FooInterface;
use BarClass as Bar;
use OtherVendor\OtherPackage\BazClass;

class Foo extends Bar implements FooInterface
{
    public function sampleFunction($a, $b = null)
    {
        if ($a === $b) {
            bar();
        } elseif ($a > $b) {
            $foo->bar($arg1);
        } else {
            BazClass::bar($arg2, $arg3);
        }
    }

    final public static function bar()
    {
        // method body
    }
}

 

后续... ... 

 

posted @ 2014-12-19 15:32  小刘_php  阅读(111)  评论(0)    收藏  举报