PHP - includes

PHP includes are only included if the logic in the script requires them.

I created three files:

top.php


echo 'start<br />';
if (true)
  include 'true.php';
else
  include 'false.php';
echo 'end';

true.php


$var=true; /* Valid, but meaningless statement */

false.php


false /* Deliberate syntax error to see if the file was included */

When top.php executes, it does not report the error from false.php. This means placing include and require statements directly before the code which requires them allows you to create scripts that process only the files required to deliver the page.

One note: the performance improvement may not be worth the slightly more complex architecture. You may see improvements by using an accelerator, or both an accelerator and this architecture. This also requires more files, and the code needs to be modular.