Modern reading notes a PSR Standard

Source: Internet
Author: User
One, standard PSR PHP standards recommendation PHP recommended standard PSR-1 Basic code style PSR-2 strict code style PSR-3 logger interface PSR-4 automatic loading specific instructions: PSR-1 Basic code Style 1, PHP tags make With <?php?> or <?=? >2, Code UTF-83, purpose a PHP file can define symbols (classes, traits, functions and constants, etc.), or perform actions with side effects, but not both. This is a simple requirement 4, automatically load PHP follow PSR-45, the name of the class must use the camel type, and the first letter Capital 6, the name of the constant must all use capital letters, if you need to underline max_lenth7, the name of the method must use Camel, the first letter lowercase PSR-2 Strict code style (in fact is more details of the place) 1, the first to implement the PSR-1 2, indentation, recommended 4 spaces, not recommended tab because the width of different editors, and rendering effect is different, in order to get the best appearance consistency, so, ... 3. File and code line PHP files must use UNIX-style line breaks finally have a blank line, and do not use PHP to turn off the label because it will be treated as output (I have actually encountered) 4, the keyword true false are lowercase 5, the namespace after each namespace statement must follow a blank line, When all use statements are complete, a blank line is also added. 6. The bracket position of the custom body of the class, and another row 7, each property and method in the visibility class to declare the visibility. Each property of the class must declare the visibility, public private protected, etc. 8, if else such a judgment symbol plus a space if ($a = = $b) {Balabala PSR-3 Logger interface 1, the third recommendation is actually not a guideline, but an interface, rules The PHP logger component can be implemented methods, mainly some methods and parameters, here is not expanded, the more popular log component is the monologPRS-4 autoloader

Modern reading notes a PSR Standard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.