Reputation: 26281
I am using a custom error handler using set_error_handler()
. All works perfect until I get to the "Do buggy script" part. This buggy script is some integration into http://osticket.com/. Note that I have enabled all errors on the base installation of ostickets without my integration, and I get the same errors, so I know it is not a flaw in my integration.
When I run the script shown below, I get approximately 200 errors written to my log and emailed to me.
My desire is to temporarily disable set_error_handler
right before this script, and then re-enable it right when it is complete.
How is this accomplished?
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
set_error_handler("my_error_handler");
//Do normal script
//I wish to disable set_error_handler here
//Do buggy script
//I wish to re-enable set_error_handler here
//Do normal script
//Complete
function my_error_handler($e_number, $e_message, $e_file, $e_line, $e_vars) {
$message = "An error occurred in script '$e_file' on line $e_line: $e_message (error no: $e_number)";
syslog(LOG_INFO,'my_error_handler: '.$message);
$e_vars='<pre>'.print_r($e_vars, 1).'</pre>';
ob_start();
debug_print_backtrace();
$backtrace = ob_get_clean();
if (in_array(substr($_SERVER['HTTP_HOST'], 0, 5), array('local', '127.0', '192.1'))) {
echo "<div class='error'>{$message}</div><p>e_vars:</p><pre>{$e_vars}</pre><p>debug_print_backtrace:</p><pre>{$backtrace}</pre>";
} else {
error_log ($message.' e_vars=> '.$e_vars, 1, '[email protected]');
if ( ($e_number != E_NOTICE) && ($e_number < 2048)) {
echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div>';
}
}
}
?>
Within the OSTicket code, bootstrap.init() sets up error reporting. I don't wish to modify the original OSTicket code as doing so will make it more difficult to upgrade to new versions.
#Error reporting...Good idea to ENABLE error reporting to a file. i.e display_errors should be set to false
$error_reporting = E_ALL & ~E_NOTICE;
if (defined('E_STRICT')) # 5.4.0
$error_reporting &= ~E_STRICT;
if (defined('E_DEPRECATED')) # 5.3.0
$error_reporting &= ~(E_DEPRECATED | E_USER_DEPRECATED);
error_reporting($error_reporting); //Respect whatever is set in php.ini (sysadmin knows better??)
#Don't display errors
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
Upvotes: 1
Views: 3078
Reputation: 7433
Just set another do nothing function:
$my_error_handler = set_error_handler(function() { return true; });
// call OSTicket here
set_error_handler($my_error_handler);
Change return true
to return false
to execute PHP internal error handler.
Upvotes: 5