Good code writing habits can make people pleasing to the eye, the following this article to share the code of PHP to meet the PSR programming specifications, the need for friends can refer to, let's take a look at it.
Objective
About the development of the standard this piece, can say has always been different styles, each home has a play, folk is also a personal play. At present, our domestic more well-known frameworks (Yii,laravel) have supported composer and joined the Php-fig (PHP Framework program group).
The automatic loading of composer supports php-fig specified PSR-0 and PSR-4 specifications to implement the automatic loading mechanism, and composer recommended PSR-4
Php-fig
This is a voluntary informal body, but in terms of the current impact on us, it may have been the default for a public trust organization, indeed has made a lot of very good norms
At present, from the official website, has voted (http://www.php-fig.org/psr/) passed the 7 large specifications
PSR-0 Automatic loading specification (officially obsolete, mostly php5.3 without namespace previously)
PSR-1 Coding Specification
PSR-2 Coding Style Recommended
PSR-3 Log Interface
PSR-4 improved automatic loading specification (official recommendation, the specification is more concise conditioning clear)
PSR-6 Cache Interface
PSR-7 HTTP Message interface
Instance
<?phpnamespace Standard; Top namespace//empty line use Test\testclass;//use introduces class/** * Class Description * * Class name must be capitalized at the beginning of the hump. */abstract class Standardexample//{} must be wrapped with a newline {/** * constant description. * * @var String */const THIS_IS_A_CONST = '; Constant all uppercase underline split/** * attribute description. * * @var String */public $nameTest = '; The property name suggests that the lowercase hump//member property must be added public (cannot be omitted), private, protected modifier/** * Property Description. * * @var String */private $_privatenametest = '; Class Private member property, "personal advice" underline lowercase start Hump/** * constructor. * * Constructor Description * * @param string $value parameter name/description */Public function __construct ($value = ")//Member method must add public (cannot be omitted), privat E, protected modifier {//{} must be wrapped $this->nametest = new TestClass (); Chained Operation $this->nametest->functionone ()->functiontwo ()->functionthree (); A piece of code logic to complete the line break/\ Code ...} /** * Member method name. * * Member Method Description * * @param string $value parameter name/description * * @return return value type return value Description * Return value type: string,array,object,mixed (multiple, indeterminate), VO ID (no return value) */Public Function testfunction ($value = ')//member method must start with a lowercase hump {//Code ...} /** * Member method name. * * Member Method Description * * @param string $value parameter name/description * * @return return value type return value Description */Private Function _privatetestfunction ($val UE = ')//Private Member method "personal suggestion" underline lowercase start Hump {//code ...}/** * Member method name. * * Member Method Description * * @param string $value parameter name/description * * @return return value type return value Description */public static function Staticfunction ($val UE = ')//static after modifier {//code ...}/** * Member method name. * * Member Method Description * * @param string $value parameter name/description * * @return return value type return value Description */abstract public Function abstractfunction ( $value = "); Abstract/** * Member method name before modifier. * * Member Method Description * * @param string $value parameter name/description * * @return return value type return value Description */FINAL public function finalfunction ($value = ')//final located before modifier {//code ...}/** * Member method name. * * Member Method Description * * @param string $valueOne parameter name/description * @param string $VALUETWO parameter name/description * @param string $valueThree parameter name/description * @param string $valueFour parameter name/description * @param string $valueFive parameter name/description * @param string $VALUESIX parameter name/description * * @return return Return value type returns a value description */Public Function toolangfunction ($valueOne = ',//variable name can be named after the first hump or underline, personal that habit, it is said that the underline readability good $valueTwo = ", $valueThree = ', $valueFour = ', $valueFive = ', $valueSix = ')//parameter too many newline {if ($valueOne = = = $valueTwo) {//Control structure plus space, same as {one Line, (right Bien Hoa) left without space//code ...} Switch ($valueThree) {case ' value '://code ... break; Default://code ... break; } do {//code ...} while ($valueFour <= 10); while ($valueFive <=) {//code ...} for ($i =0; $i < $valueSix; $i + +) {//Code ...}}}
The above is the whole content of this article, I hope that everyone's study has helped.