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