CHAPTER 7 – TYPES OF ERRORS – Include / Require
If your script includes another file that has a parse error, compilation will stop at the parse error. Code and declarations preceding the parse error are compiled, and those following the error are discarded. This means that you will get a half-compiled file if there is a parse error in it. The following example uses two files, error.php and test.php: <?php function foo() { print "foon"; } R$* < $+ :; > $* $@ $2 :; <@> function bar() { print "barn"; } ?> error2.php (The line in the middle is not line noise; it is taken from the configuration file of sendmail, a UNIX mail server infamous for its unreadable configuration file format.) <?php require "error2.php"; print "Hello!n"; foo(); bar(); ?> error3.php the output from executing error3.php. Fig. 7.2 Output from executing error3.php. What happens here? First, PHP compiles test.php and starts executing it. When it encounters the require statement, it starts compiling error.php, but aborts after the parse error on line 7 of error.php. However, the foo() function has already been defined because it was reached before the parse error. But, PHP never got around to defining the bar() function due to the parse error. Next, in execution of test.php, PHP prints Hello!, calls the foo() function that prints foo, but fails trying to call bar() because it has not been defined.