PHP – Zend Coding-Style

Zend Coding Style

  • no closing tags (?>) on PHP-only files (to prevent accidental header sends)
  • indentation 4 spaces
  • line length 80 chars soft limit, 120 chars hard limit
  • Line endings LF
  • Class names: Capitalized_Words_Only_first_Char_Pdf
  • abstract class: Capitalized_Words_Only_first_Char_PdfAbstract (Abstract added, without an underscore)
  • Interface naming: Capitalized_Words_Only_first_Char_PdfInterface (Interface added, without an underscore)
  • Filenames: alphanumeric characters, underscores, and the dash character ("-") are permitted; no spaces (eg. Zend/View/Helper/FormRadio.php)
  • functions: camelCase(), numbers allowed but to be avoided, no underscores
  • variables: $camelCase, numbers allowed but to be avoided, no underscores
    • private and protected: prepend an underscore ($_camelCase)
  • constants: ALL_CAPSULATED_WORDS seperated by underscores, numbers allowed
    • global constants (via define()) discouraged
  • PHP code always between <?php and ?> (exception omitted ?>, see above)
  • the 'single quotes' over "double quotes", double quotes (") for readability
  • multiline strings with dot (.) under the assignment operator (=)
  • variable substitution "text $var text" or "text {$var} text"
  • string concatenation with dots with a space before and after ('str' . 'str2')
  • space after comma, like, this
  • multiline array declarations: indent next line to begin where the declaration of prior line begins (after opening paranthesis ()
    • or put decl. start at next line and indent. closing parenthesis on the level of first line
  • multiline associate arrays (external link) discouraged

+http://framework.zend.com/manual/en/coding-standard.coding-style.html#coding-standard.coding-style.classes