Chapter 4. Learning PHP Syntax and Variables

In this chapter, we cover the basic syntax of PHP — the rules that all well-formed PHP code must follow. We explain how to use variables to store and retrieve information as your PHP code executes and the type of system that governs what kinds of values can be stored in the first place. Finally, we look at the simplest ways to display text that will show up in your user's browser window.

PHP Is Forgiving

The first and most important thing to say about the PHP language is that it tries to be as forgiving as possible. Programming languages vary quite a bit in terms of how stringently syntax is enforced. Pickiness can be a good thing because it helps make sure that the code you're writing is really what you mean. If you are writing a program to control a nuclear reactor and you forget to assign a variable, it is far better to have the program be rejected than to create behavior different from what you intended. PHP's design philosophy, however, is at the other end of the spectrum. Because PHP started life as a handy utility for making quick web pages, it emphasizes convenience for the programmer over correctness; rather than have a programmer do the extra work of redundantly specifying what is meant by a piece of code, PHP requires the minimum and then tries its best to figure out what was meant. Among other ...

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.