|
Chapter 15
Ten Things to Look For When
Troubleshooting a Script
In This Chapter
Recognizing common PHP errors
Interpreting error messages
I
guarantee that you will do all the things that I mention in this chapter. You
just can’t write scripts without making these mistakes. The trick is to train
yourself to recognize them, roll your eyes, say, “Not again,” and just fix them.
One error message that you’ll see many times is
Parse error:parse error in c:\test.phpon line 7
This is PHP’s way of saying “Huh?” It means that it doesn’t understand some-
thing. This message helpfully points to the file and the line number where PHP
got confused. Sometimes it’s directly pointing at the error, but sometimes
PHP’s confusion results from an error earlier in the script.
Here are ten of the most common errors and how to avoid them.
Missing Semicolons
Every PHP statement ends with a semicolon (
;
). PHP doesn’t stop reading a
statement until it reaches a semicolon. If you leave out the semicolon at the
end of a line, PHP continues reading the statement on the following line. For
example, consider the following statement:
$test = 1
echo $test;
|