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 😉
- 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.
- Capitalize on the first letter of each word in the file and directory names.
- 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)
- Begin the names of private and protected properties with an underscore.
- Use UPPERCASE only for constants. Separate each word with an underscore.
- Always use the full opening PHP tag. “<?php”
- Omit closing PHP tag “?>” in files that contain only php code. This prevents whitespace triggering the “headers already sent” error when using includes.
- Indent 4 spaces
- Restrict lins to a maximum of 80 characters
- Always use single quotes unless they contain variables to be processed.
- Put a space on either side of the concatenation operator “ . “ for readability.
- Insert space after comas for readability.
- Break Associative arrays into multiple lines. Use white space padding to align both keys and values.
- Put open and closing braces of classes and functions on separate lines.
- Put the opening brace of conditional statement on the same line as the condition, but the closing brace on a line of its own.
- Use PHPDoc formatted comments.