Share PHP instances that comply with the PSR programming specifications, and phppsr programming instances
Preface
With regard to the development standard, it can be said that there have always been different styles, each of which has its own gameplay, and even more private. At present, several well-known frameworks in China (Yii, Laravel) have supported Composer and joined the PHP-FIG (php Framework Program Group ).
The automatic loading of Composer supports the PHP-FIG and PSR-0 specifications specified by the PSR-4 to achieve the automatic loading mechanism, and Composer recommends the use of PSR-4
PHP-FIG
This is a voluntary and informal institution, but from the perspective of the current impact on us, it may have already been a public trust organization by default, and many very good regulations have been formulated.
At present, from the official website, has been voted (http://www.php-fig.org/psr/) through 7 large specifications
- PSR-0 automatic loading specification (officially obsolete, mainly because php5.3 has no namespace before)
- PSR-1 coding Specification
- PSR-2 coding style recommendation
- PSR-3 log Interface
- PSR-4 improved automatic loading specifications (official recommendations, specifications more concise clear conditioning)
- PSR-6 cache Interface
- PSR-7 HTTP message interface
Instance
<? Phpnamespace Standard; // namespace on the top // empty line use Test \ TestClass; // use Introduction Class/*** class description ** the class name must start with an upper case. */abstract class StandardExample // {} must wrap {/*** constant description. ** @ var string */const THIS_IS_A_CONST = ''; // all constants are separated by uppercase underscores (_)/*** attribute description. ** @ var string */public $ nameTest = ''; // The property name is recommended to start with" lower case ". // public (cannot be omitted) and private must be added to the member attribute, protected modifier/*** attribute description. ** @ var string */private $ _ privateNameTest = ''; // class private member attributes. [personal suggestion] the upper case of the underscore (_) begins with the upper case and the lower case. *** constructor. ** constructor description ** @ param string $ value parameter name/Description */public function _ construct ($ value = '') // The member method must be added public (cannot be omitted), private, and protected modifier {// {} must wrap $ this-> nameTest = new TestClass (); // chain operation $ this-> nameTest-> functionOne ()-> functionTwo ()-> functionThree (); // line feed after a piece of code logic is executed // code ...} /*** member method name. ** member method description ** @ param string $ value parameter name/description ** @ return value type return value description * return value type: string, array, object, mixed (multiple types, uncertain), void (no return value) */public function testFunction ($ value = '') // The member method must start with a lower-case camper {// code ...} /*** member method name. ** member method description ** @ param string $ value parameter name/description ** @ return value type return value description */private function _ privateTestFunction ($ value = '') // Private member method [personal suggestion] the upper case of an underscore (_) and the upper case of a hump {// code ...} /*** member method name. ** member method description ** @ param string $ value parameter name/description ** @ return value type return value description */public static function staticFunction ($ value = '') // static is located after the modifier {// code ...} /*** member method name. ** member method description ** @ param string $ value parameter name/description ** @ return value type return value description */abstract public function invoke actfunction ($ value = ''); // abstract is located before the modifier/*** member method name. ** member method description ** @ param string $ value parameter name/description ** @ return value type return value description */final public function finalFunction ($ value = '') // final is located before the 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 value type return value description */public function tooLangFunction ($ valueOne = '', // The variable name can start with a lower-case letter and start with a hump or underline. In my habits, it is said that the underline is good for readability $ valueTwo = '', $ valueThree ='', $ valueFour = '', $ valueFive = '', $ valueSix ='') // wrap too many parameters {if ($ valueOne ===$ valueTwo) {// control structure => with spaces, the same {Line, (right and) with no space on the left // code ...} switch ($ valueThree) {case 'value': // code... break; default: // code... break;} do {// code ...} while ($ valueFour <= 10); while ($ valueFive <= 10) {// code ...} for ($ I = 0; $ I <$ valueSix; $ I ++) {// code ...}}}
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.