

Ask YC: PHP Coding Standards? - trickjarrett

Do you guys follow any coding standards with PHP? I'm pushing my office to adopt some more than just the basic understood baseline of variables at the top of functions, etc.<p>PEAR? Or some other set?<p>Thanks guys!
======
leftnode
Here is the coding standard I've written for my open source project
(<http://artisansystem.com>):

<http://docs.artisansystem.com/index.php/Coding_Standard>

They can be a little verbose at first, but they make for better readability.

~~~
trickjarrett
Thanks! I'll take a look at it. Any specific things you want to highlight as a
strength for the system?

~~~
leftnode
Its basically a list of things I've done over the years to make my code more
readable as I go to great lengths to make it readable (to the point that
people have accused me of being too verbose).

Before I moved to functionalized queries, I would always make my queries look
as formatted as possible, especially when they contained a lot of joins.

Also, my biggest pet peeve is not having braces around large case statements
as it makes it difficult to find the next case statement, I like using my
editor to find the matching brace.

------
elviejo
1\. I use the PEAR standard: Well defined, popular, and plenty of code written
in it.

2\. Use php_CodeSniffer to check if yout code coonforms to the standard.
<http://matrix.squiz.net/developer/tools/php_cs>

3\. Make CodeSniffer a pre-commit hook so that when you commit co to SVN it
doesn't let you until, your code follows the standard.

and done.

