Winnipeg Photographer


Zend Framework PHP Coding Standard Overview

This post will go over the “Zend Framework PHP Coding Standard” in a very brief overview. Like most things I tend to use this website as reminders to myself. I hope this helps you as well ;)

Naming Conventions

  1. Use class names that map to the directory of the structure in which the class is stored by prefixing the class name of each directory followed by an underscore. All my personal classes might be saved to the “Jh” Directory. So the class in “Validator.php” is called Jh_Validator.
  2. Capitalize on the first letter of each word in the file and directory names.
  3. Use descriptive names for methods and properties. Where they consist of more then one word, each additional name should begin with a capital letter. ie. (validateFirstName)
  4. Begin the names of private and protected properties with an underscore.
  5. Use UPPERCASE only for constants. Separate each word with an underscore.

Coding Style

  1. Always use the full opening PHP tag. “<?php”
  2. Omit closing PHP tag “?>” in files that contain only php code. This prevents whitespace triggering the “headers already sent” error when using includes.
  3. Indent 4 spaces
  4. Restrict lins to a maximum of 80 characters
  5. Always use single quotes unless they contain variables to be processed.
  6. Put a space on either side of the concatenation operator “ . “ for readability.
  7. Insert space after comas for readability.
  8. Break Associative arrays into multiple lines. Use white space padding to align both keys and values.
  9. Put open and closing braces of classes and functions on separate lines.
  10. Put the opening brace of conditional statement on the same line as the condition, but the closing brace on a line of its own.
  11. Use PHPDoc formatted comments.

Leave a Reply