PHP coding standard

by saravana 2013-06-04 15:47:45

Naming Conventions
As with any programming language, following naming conventions ultimately makes your code easier to read and maintain. Here's a few rules to follow:

*Class names use PascalCase.
*Method names should be in camelCase.
*Constants require all capital letters, separating each word with an underscore (e.g. CONSTANT_VARIABLE).

Code Conventions
There's more, follow these guidelines as well:

* Only use
* Files should either declare symbols or use them.
* Files must be in UTF-8 format without BOM for PHP code

The Advanced Coding Standard

* Four spaces should be used instead of tabs.
* The ideal line length should be under 80 characters, but a soft limit of 120 characters should be imposed on all lines.
* There should be one blank line under the namespace and use declarations.
* A method's or class's opening brace must be on its own line.
* A method's or class's closing brace must go on the line immediately after the body.
* All properties and methods require a visibility level.
* The 'abstract' / 'final' keywords should appear before the visibility while 'static' goes after.
* Control structure keywords must be followed by one space.
* A control statement's opening brace should appear on the same line as the statement.

Most of these are self-explanatory, but the middle convention is slightly confusing. It essentially dictates that any declaration, be it functions, classes, etc., should be separated into their own files. This not only promotes best practices like code-reuse and separation, but it keeps your code neat and clean.
742
like
0
dislike
0
mail
flag

You must LOGIN to add comments