John Esposito edits Refcardz at DZone, while writing a dissertation on ancient Greek philosophy and raising two cats. In a previous life he was a database developer and network administrator. John is a DZone Zone Leader and has posted 320 posts at DZone. You can read more from them at their website. View Full User Profile

Writing Better PHP: Three Guides

  • submit to reddit

It's true that, in some sense, programming is all the same; and in some sense, thinking about assembly is a good way to think about programming in general. But even if 'assemble, link, load' is a good way to think about programming, it's probably a very confusing way to think about programs written in a high-level language.

Sometimes, then, improving your generic 'programming brain' will help you improve your facility with a particular language. At other times, it's more important to learn the nuances of a language, paying close attention to the kind of applications the language is used for. Like as a carpenter can improve his general ability to measure things, or learn a lot about lathes in particular -- and in fact the carpenter always needs to improve both.

For improving your PHP, then, you can do two things: become a better programmer; and understand PHP more finely, more deeply.

These three guides better your PHP, ordered from most programming-general to most PHP-specific:

  • 10 Tips for Writing Better PHP Code is really ten tips for writing better code, period. You probably won't learn anything absolutely new from this guide ('name your variables and functions well', 'comment your code', 'test your code often'), but it reminds you of the basics and offers a few reasons for why best general programming practices are particularly important for apps written in PHP. 
  • How To Write Better PHP Code: These 7 Ways addresses some temptations PHP developers are especially likely to face (not using templates, encapsulating too little, confusing PHP and SQL for CRUD), and offers ways to eliminate kinds of sloppiness especially likely to harm the performance of PHP apps ('reduce db queries' for high-volume web applications, for example).
  • The How to write better PHP code sticky on's PHP forum zeroes in on issues extremely specific to PHP and web applications (keeping HTML, CSS, JavaScript, and PHP separate; evil magic quotes; avoiding XSS attacks with htmlentities()) and particular systems commonly used with PHP (MySQL, JavaScript, Bash. This is the best resource for 'always do this particular thing that wouldn't have been obvious to anyone lacking PHP/MySQL experience, even if said person is a good programmer in general'.

All three are worth reading, depending on what you're going for.