Darryl Hein Darryl Hein - 2 years ago 128
PHP Question

Should PHP code have spaces before operators?

I've seen a lot of code recently formatted as the following:


if ($var=='test'){
// do something

Personally I don't like it and would prefer it as:


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

I think it's much more readable (note the addition of spaces).

Is there a general preference in the community or is one way better than another.

Answer Source

The most important thing is to follow a standard and stick to it.

That said maybe you can follow Zend's Framework standards and they use spaces. Check C.4.6.

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

Hope it helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download