phppsr-12

PHP var declaration best practices


I always try to code with the best practices possible, and regarding PHP, I use mainly the PSR-12 standards.

Now regarding var declarations, is it "wrong" to use tabs like the example below?

$a      = 1;
$abc    = 2;
$abdef  = 3; 

Or should I keep without tabs?

$a = 1;
$abc = 2;
$abdef = 3; 

I'm asking this because the first option looks more readable for the developer.


Solution

  • It depends from the codestyle of the project. The worth case if in one file you'll have variables with tabs, and in second without.

    Second option is more classic, so I advice you to use it. Also you can look to some big opensource projects like symfony or laravel, and try to make it in similar way :)

    https://github.com/laravel/laravel

    https://github.com/symfony/symfony