Zend framework 1 article

Home >> Zend framework 1 >>

  Zend framework coding standard

Many developers using Zend Framework have also found these coding standards useful because their code's style remains consistent with all Zend Framework code. Coding standards are important in any development project, but they are particularly important when many developers are working on the same project. Coding standards help ensure that the code is high quality, has fewer bugs, and can be easily maintained.

1. File Formatting Standard

  • PHP File Formatting
    PHP code, the closing tag ("?>") is never permitted.
     
  • Indentation
    Indentation should consist of 4 spaces. Tabs are not allowed.
      
  • Maximum Line Length
    The target line length is 80 characters. That is to say, Zend Framework developers should strive keep each line of their code under 80 characters where possible and practical. However, longer lines are acceptable in some circumstances. The maximum length of any line of PHP code is 120 characters. 

2. Naming Conventions Standard

  • Classes
    Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged in most cases. Underscores are only permitted in place of the path separator; the filename "Zend/Db/Table.php" must map to the class name "Zend_Db_Table".
     
  • Abstract Classes
    In general, abstract classes follow the same conventions as classes, with one additional rule: abstract class names must end in the term, "Abstract", and that term must not be preceded by an underscore. As an example, Zend_Controller_Plugin_Abstract is considered an invalid name, but Zend_Controller_PluginAbstract or Zend_Controller_Plugin_PluginAbstract would be valid names.
     
  • Interfaces
    In general, interfaces follow the same conventions as classes, with one additional rule: interface names may optionally end in the term, "Interface", but that term must not be preceded by an underscore. As an example, Zend_Controller_Plugin_Interface is considered an invalid name,but Zend_Controller_PluginInterface or Zend_Controller_Plugin_PluginInterface would be valid names.  
     
  • Filenames
    For files, only alphanumeric characters, underscores, and the dash character ("-") are permitted. Spaces are strictly prohibited. Any file that contains PHP code should end with the extension ".php", with the notable exception of view scripts. The following examples show acceptable filenames for Zend Framework classes:
    // acceptable filenames for Zend Framework
    Zend/Db.php
    Zend/Controller/Front.php
    Zend/View/Helper/FormRadio.php
  • Functions and Methods
    Function names must always start with a lowercase letter. When a function name consists of more than one word, the first letter of each new word must be capitalized. This is commonly called "camelCase" formatting.
    // These are examples of acceptable names for functions:
    filterInput()
    getElementById() 
  • Variables
    Variables that are declared with the "private" or "protected" modifier, the first character of the variable name must be a single underscore. Member variables declared "public" should never start with an underscore.
  • Constants
    All letters used in a constant name must be capitalized, while all words in a constant name must be separated by underscore characters. For example, EMBED_SUPPRESS_EMBED_EXCEPTION is permitted but EMBED_SUPPRESSEMBEDEXCEPTION is not.

These all are the basic coding standards you can in more details on Zend framework official site

Write your comment now