Opinion on PSR-1: Basic Coding Standard

After reading PSR-1, some thoughts came up that I would like to share with the programming community in order to get stories about your experience.






PSR-1: Basic Coding Standard - A standard that recommends rules for formatting and coding. Styling  is how to write code, and  writing  is what to write.





Subtext PSR-1 says that you should not use mixing of code and logical conclusions of the code. I put it a little not clearly, but then you will understand that PSR-1 does not recommend writing a class, displaying it on the screen and initializing properties in one file.





All PHP files must use either  <?php



or  <?=



. Everything is obvious and understandable here, the first tag says about the declaration of a php code section, and the second is a short record  <?php echo



, that is, output.





Files should also be in UTF-8 encoding without BOM, which makes sense. There were some cases in a project where there were several programmers. So, there one somehow managed to insert a BOM symbol and because of this, parsing files broke.





It also states that it is not recommended to use multiple side effects. With the translation, I'm not always all right ... That is, we cannot take and write in the file:





<?php
// side effect: change ini settings
ini_set('error_reporting', E_ALL);

// side effect: loads a file
include "file.php";

// side effect: generates output
echo "<html>\n";

// declaration
function foo()
{
    // function body
}
      
      



Well, here the moment is extremely controversial. Although the standard recommends using an autoloader according to its PSR-0 and PSR-4 standards. On the one hand, yes, but there can be application initialization at a single entry point. In short, the moment is doubtful. In the same Yii2 this approach is not followed ... I would not pay attention to this very recommendation.





(namespace). , , .  StudlyCaps



. PHP < 7.0, , .





,  DATE_APPROVED



. , – . .





. PSR-1 : $StudlyCaps



$camelCase



,  $under_score



. . , , , ,  $camelCase



. , , ... , .  camelCase



.





With the naming of methods in the format  camelCase()



 I completely agree and maintain. It is logical that we name classes with a capital letter, constants with a small letter, methods with a small letter. And, in principle, you can distinguish one from the other simply by writing.





Thank you for your attention, I hope that the material was useful, although it is a statement of thoughts on reading PSR-1.








All Articles