PHP The Right Way

Last week, I wrote two articles discussing code quality when working on WordPress-specific projects:

Both of the articles lead to good comments, links, and thoughts from you guys. Though many of us are familiar with the WordPress Coding Standards, they don’t cover everything.

Rachel Baker shared a link to PHP The Right Way – a solid resource for writing PHP-based code when the coding standards leave something to be desired.

Ultimately, the point of having coding standards – and participating in code reviews – is so that the code is consistent. That is, code should look as if the same person has written it regardless of who actually wrote it.

I think the WordPress Coding Standards provide a really good foundation for writing WordPress code. In fact, I think that it covers a significant amount of information for people who are developing themes and plugins.

But if you’re working on something more advanced or writing something more complex such as an advanced plugin or an application, then there may be certain things that the standards don’t cover and it’s important to have something to which we can default.

Here’s a very simple example: The coding standards don’t cover how to handle PHPDoc conventions because those conventions are platform agnostic and are already in place in the PHP community.

PHP The Right Way should fill in the gaps whenever you find stumble into an area where you’re unsure of the best way to format your code:

There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and bad code. This must stop. PHP: The Right Way is an easy-to-read, quick reference for PHP best practices, accepted coding standards, and links to authoritative tutorials around the Web.

The reference covers topics like:

  • Conditionals
  • Namespacing
  • Exceptions
  • Variable Declarations

And even more advanced things such as Design Patterns, handling databases, and performing testing.

Though some of the articles will be irrelevant if you work strictly with WordPress, I highly recommend checking out the Coding Practices section.