Last Updated: February 25, 2016
· rougin

Follow Coding Style Standards in PHP

Everyday we develop applications (like for example in PHP) and sometimes we write codes that doens't follow the standards of coding style.

Why follow some certain styles when i want to type a code what i want?

When I was a novice programmer (back in the time that i'm using C language), I really don't have a certain coding style or naming conventions. I just enter int x = 0; float y = 1; and so on. Which makes my professors having trouble looking at my code. As the time goes by, I realized that I need to follow some certain coding style standards so that the other developers or my workmates can understand my work and it also makes the code clean and consistent.

I get your point. But there is no time to fix my code to follow some coding style standards.

Worry no more, there are some solutions to that problem.

PHP CodeSniffer - a PHP5 script that tokenises PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

PHP CS Fixer - this tool fixes most issues in your code when you want to follow the PHP coding standards as defined in the PSR-1 and PSR-2 documents.

Using other coding styles is good. But if you follow the coding style standards in PHP, it will make your code better and maintainable. And don't be afraid to accept a new coding style standard! It is just simply a challenge for you. For more information about the coding style standards in PHP, just go to the sites below:

PHP: The Right Way

Read about PSR-0

Read about PSR-1

Read about PSR-2

Read about PSR-4

Read about PEAR Coding Standards

Read about Zend Coding Standards

Read about Symfony Coding Standards

Say Thanks