I have a custom error handler set up using set_error_handler
. When I tried to include a file that doesn't exist, PHP calls error_handler one more time than it should:
<?php
error_reporting(E_ALL | E_STRICT);
set_error_handler(function($errno, $errstr, $errfile, $errline, $errcontext){
if(error_reporting() !== 0){
echo "<br>";
echo "<br>In Custom Error Handler...";
echo "<br>Err String: ", $errstr;
echo "<br>Passing to Default Handler...";
}
return false; // allow default
});
include("/missing_file.php"); // line 11
?>
Output:
In Custom Error Handler... // this is the extra error handler call
Err String: include(/missing_file.php) [function.include]: failed to open stream: No such file or directory
Passing to Default Handler...
// the default handler does nothing, even though error_reporting is not zero
// Next Phase:
In Custom Error Handler...
Err String: include() [function.include]: Failed opening '/missing_file.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')
Passing to Default Handler...
Warning: include() [function.include]: Failed opening '/missing_file.php' for inclusion in /home/yccom/public_html/apr/test.php on line 11
The same behavior is observed with require
.
For example, changing line 11 to require
will give this output:
In Custom Error Handler... // this is the extra error handler call
Err String: require(/missing_file.php) [function.require]: failed to open stream: No such file or directory
Passing to Default Handler...
// the default handler does nothing, even though error_reporting is not zero
// Next Phase:
Fatal error: require() [function.require]: Failed opening required '/missing_file.php' in /home/yccom/public_html/apr/test.php on line 11
What may be causing the error handler's additional call?