Skip to content
Advertisement

Force PHP to execute include even if there is an error later in the script

I am trying to create a system where by adding one include, I can set PHP to display errors (the php.ini file prevents this). In other words:

<?php
    include "showerrors.php";
    // Produce Error
    ERROR;
?>

This would create a parse error and “showerrors.php” does not get executed, meaning that the error never gets shown. However, if “showerrors.php” does get executed, the error would be shown.

Advertisement

Answer

If you have a parse error, i.e. invalid syntax, then no code in the file will be executed because the file can’t be parsed. That includes include statements. As simple as that, no way around it. It’s not difficult to make sure your file has at least correct syntax, such tools are integrated into most editors and IDEs.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement