PHP Coding Standards for Developers
In this article you will find basic PHP coding standards that must be followed by every PHP developer in order to make their code more presentable and understandable one to the peer programmers.
For every developer it is important to follow coding standards in order to
make their code more readable and understandable one to your peer programmers.
If you are not aware of the basic PHP coding standard, you must learn it before
starting the development process. Though every organization follows their own
set of coding standards that might be different from others. But the basic PHP
Coding Standards remains same for everyone. For example a Class name or Method
and Function name in PHP must start with the uppercase letters. The name of the
Class, Method and Function must be unique and understandable one.
So, it is a necessary for every developer to follow the PHP coding standards
to make their code manageable and reusable one.
Benefits of using PHP coding standards
- It makes program more manageable and readable one.
- It enable any developer to start working quickly without much efforts.
- Program codes can be reused for the development purpose.
- Less chance of making mistakes by new developers.
Given are few basic PHP Coding Standards that must be followed by any PHP
developer, while writing their code.
- Indenting: Use logical and consistent indent style to makes your code
more readable. for example you can use an indent of 4 spaces with no tabs.
- Methods, functions and variables name must start with the capital
- Variable names must be unique and understandable.
- Function name must be understandable. Avoid using of underscores while
declaring functions names.
- Define Class name with uppercase letters and underscore.
- Do not use libraries and codes from external sources without prior
checking of compatibility with your software. Also take approval before
using it as it might be in use already or there could be other issues
related to licensing and performance.
- Comments - Write your comments within specified comment blocks. PHP
supports three types of comment style. C style comments " /* Comment type
1*/ ", . C++ style comments " // Comment type 2 " are commonly used.
But Perl/shell style comments " # comment type 3 " is discourage from use.