Should PHP code have spaces before operators?

I saw a lot of recently formatted code:

Answer:

if ($var=='test'){
    $var=Foo('blah'.$var1);
}else{
    // do something
}

Personally, I don't like this, and I would prefer:

B:

if ($var == 'test') {
    $var = Foo('blah' . $var1);
} else {
    // do something
}

I think this is much readable (pay attention to adding spaces).

Are there common preferences in the community, or is one better than the other?

+3
source share
5 answers

The most important thing is to follow the standard and adhere to it.

Perhaps you can follow Zend Framework standards and use spaces . Check C.4.6 .

if ($a != 2) {
    $a = 2;
}

Hope this helps!

+11
source

+1 for spaces :)

, ,

+3

PHP C . , , , .

, :

if ($foo) {

MySuperDuperFunction($foo);

:

switch ($bar) {
    case CONSTANT:
        more_code();

..

switch ($bar) {
case CONSTANT:
    more_code();

, , . .

. PHP, C, .

- :

if($a==2&&b==1&&c>3)
{

, . :

if (
    a==2
     &&
    b==1
     &&
    c>3
)
{

... , LISP!

+1

, .

Zend Framework PEAR. , , .

.

0

- , , , - .

PSR-2, , . , .

0

Source: https://habr.com/ru/post/1721896/


All Articles