Search code examples
phpcoding-stylepsr-2

PHP PSR-2 new lines before/ after statments


Example no 1:

$something = [1,2,3,4]
foreach ($something as $key => $value) {
    //code code code
}
$something2 = [];

I can't find clear answer about new live before and after foreach, what PSR-2 say about that ?


Solution

  • Point 2.3 "Lines" Make it optional to add blank lines before and after statements. It is still useful to separate code blocks in "paragraphs" to improve logic comprehension and readability.

    Blank lines MAY be added to improve readability and to indicate related blocks of code.