PHP coding standards I agree with

In all my time coding php I have read a lot of php coding standards.

Finally I have found one that I almost agree with completely. My only wobble is regarding the suggestion not to use getters and setters in classes.

PHP Coding standards

The PHP Coding Standard is with permission based on Todd Hoff‘s C++ Coding Standard.
Rewritten for PHP by Fredrik Kristiansen / DB Medialab, Oslo 2000-2003.

2 comments.

  1. I occasionally see code like this:

    if ($very_long_condition && $second_very_long_condition)
    {

    }
    else if (…)
    {

    }

    However I prefer

    if ($very_long_condition && $second_very_long_condition){

    }
    else if (…){

    }
    I’m not sure why however it just “feels” right.

  2. @PHP Designer

    I always put curly braces on their own line. I do this because php is whitespace tollerant and you can (and should) use as much as needed to make your code readable.

    I personally think that

    
    elseif($condition)
    {
    	doSomething();
    }
    

    is easier to read than

    
    elseif($condition){
    	doSomething();
    }
    

    or

    
    elseif($condition){
    
    	doSomething();
    }