Firstly, if you use require , it will always kill your application if the file cannot be included. There is no control over the result, you can do nothing after that. If you want to monitor the success of file inclusions, use include and check its return value.
$success = include "foo.php"; if (!$success) {
You may have syntax differences, for example:
if (!(include "foo.php")) ...
This will trigger E_NOTICE if the file cannot be included, which you cannot catch. But this is normal, as it will help you debug the problem, and the error display will be disabled in the process anyway (right, right?).
or throw new Exception does not work because throw is an operator and cannot be used where an expression is expected.
If you want to catch syntax errors in the included file, use php_check_syntax / it successor php -l <file> .
source share