UIFC PHP Coding Standards

Contributors to UIFC should adhere to the coding standards outlined in this document. Doing so will ease the task of maintaining this large and complex code base. Unless indicated as "encouraged" or "preferred", all items should be considered required.
This document is adapted in part from the PEAR Coding Standards

Indenting

Indents should be 4 spaces with no tabs. Eight shalt thou not indent, nor either indent thou three, excepting that thou then proceed to four.

Wrapping

All code should be wrapped so that lines are no longer than 80 characters.

Function definitions

Function definitions should follow the convention of keeping the initial brace on the first line:
        function myFunction($arg1, $arg2) {
            if (condition) {
                statement;
            }
            return $val;
        }
    

Function Calls

Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon.
       $var = foo($arg1, $arg2, $arg3);
    

Control Structures

Control structures should always use braces, even in situations where they are not technically required. There should be a space between the control keyword and the opening parenthesis to distinguish them from function calls. The use of switch statements over complex if/else structures is encouraged.
        if (condition) {
            statement;
        } elseif(condition) {
            statement;
        } else {
            statement;
        }
        
        switch (condition) {
            case 1:
                action1;
                break;
                
            case 2:
                action2;
                break;
                
            default:
                defaultAction;
        }              
    

Naming Conventions

Functions and methods should be named using "camel notation" or "bumpy case". The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized.
       $var = foo($arg1, $arg2, $arg3);
    
Private methods and variables in a class, which are only intended to be called from within their parent class, should be prefixed with a single underscore.
        _myPrivateMethod();
        $this->_init();     
    
Variables should use "camel notation" or "bumpy case".
        $thisIsMyVariable
        $loginName
    
Constants should be uppercase with underscores to separate words. Constants should be prefixed with the class or package name followed by an underscore where applicable.
        WIDGET_MY_CONSTANT
        DB_FILE_DIR
    
Global variables should begin with a single underscore followed by class or package name.
        $_STYLIST_myVariable
    

Commenting

Inline documentation in the form of coments that describe the use of classes, methods, and functions should follow the PHPDoc convention, which is based on JavaDoc. Comments should be made using either C style or C++ style comments (/* */ or //) are acceptable. If it really makes you happy, you may use "#", but only for non-documentation comments.
Doc Comments are required for all classes, methods and functions, whether public or private. Refer to the document How to Write Doc Comments for the Javadoc Tool for a complete description of how to write Doc Comments.
A summary of the tags currently supported by PHPDoc can be found here.

CVS

Every file must include the $Id: Coding_Standards.html,v 1.1 2001/10/13 23:13:42 ebraswell Exp $ CVS keyword. You should also use the $Revision: 1.1 $ keyword in the @version PHPDoc tag.

PHP Code tags

Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is the most portable way to include PHP code on differing operating systems and setups and is required for XML 1.0 and XHTML 1.0 compliance.




Author: Eric Braswell
$Id: Coding_Standards.html,v 1.1 2001/10/13 23:13:42 ebraswell Exp $