Chapter 32. Learning PHP Style

This chapter is about the major points of PHP style and how it can enhance the functionality, maintainability, and attractiveness of your code. This discussion is intended to help new PHP developers make the main stylistic decisions, most of which are common to all programming languages.

We also hope this chapter may help new PHPers decipher other people's code. It can be very alarming to someone just learning scripting to read three different tutorials, which appear totally incongruent but lack any explanation of the discrepancies. The information in this chapter will help you tease out the functionally important bits of code from the mere stylistic quirks and thus gain a better understanding of what you're seeing.

The Uses of Style

The primary goal of a program is, of course, functionality. After all, if your PHP script chokes, who's even going to care how good it looks? Error messages are never all that stylin'. But there is a vast difference between simply whipping up something that will work and writing well-formed code that can be clearly understood by others.

PHP programmers confront all the same style issues that other programmers do, including:

  • Readability: Sure, you understood it when you wrote it, but what about the next person who reads it? What if the next person is you?

  • Maintainability: What happens when your ...

Get PHP6 and MySQL® 6 Bible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.