Specifications

These errors can be hard to find if they result from a combination of multiple files. They can
also be difficult to find if they occur in a large file. Seeing “parse error on line 1001” of a
1000 line file can be enough to spoil your day.
In general though, syntax errors are the easiest type of error to find. If you make a syntax error,
PHP will give you a message telling you where to find your mistake.
Runtime Errors
Runtime errors can be harder to detect and fix. A script either contains a syntax error or it does
not. If the script contains a syntax error, the parser will detect it. Runtime errors are not caused
solely by the contents of your script. They can rely on interactions between your scripts and
other events or conditions.
The following statement
include (“filename.php”);
is a perfectly valid PHP statement. It contains no syntax errors.
This statement might, however, generate a runtime error. If you execute this statement and
filename.php does not exist or the user who the script runs as is denied read permission, you
will get an error resembling this one:
Fatal error: Failed opening required ‘filename.php’
(include_path=’.:/usr/local/lib/php’) in
/home/book/public_html/chapter23/error.php on line 1
Although nothing was wrong with our code, because it relies on a file that might or might not
exist at different times when the code is run, it can generate a runtime error.
The following three statements are all valid PHP. Unfortunately, in combination, they are
attempting to do the impossibledivide by zero.
$i = 10;
$j = 0;
$k = $i/$k;
This code snippet will generate the following warning:
Warning: Division by zero in
/home/book/public_html/chapter23/div0.php on line 3
This will make it very easy to correct. Few people would try to write code that attempted to
divide by zero on purpose, but neglecting to check user input often results in this type of error.
This is one of many different runtime errors that you might see while testing your code.
Building Practical PHP and MySQL Projects
P
ART V
480
29 7842 CH23 3/6/01 3:41 PM Page 480