Question

Which coding style choice is considered preferable by most developers?:

if ( ! isset($var) ) {

OR

if (!isset($var)) {

OR

if ( !isset($var) ) {

OR

something else...
Was it helpful?

Solution

I'd go with the third option:

if ( !isset($var) ) {

Here's why:

  • It's easy to read
  • It separates the condition from the if brackets making it less confusing
  • I don't know... personal preference?

It boils down to this: use whatever style you're comfortable with. There's no best.

OTHER TIPS

The answer for this question is really subjective, Is hard to tell which one is the most preferred one, for me the three are ok, It depends and how do you want to do it, and keep the same format all over the file.

If you are wondered about the cleanest way to coding, you can check this: http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html

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

At least, that's how Zend looks at it: http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top