A
Anonymous
Guest
I use this to stop php from reporting notice errors
I get a couple thousand in my error reporting script for a undefined index in a array. That should take care of the notices in my error report right? unfortionatly it does not. I on the top of my other scripts too.
Code:
error_reporting(E_ALL ^ E_NOTICE);
I get a couple thousand in my error reporting script for a undefined index in a array. That should take care of the notices in my error report right? unfortionatly it does not. I on the top of my other scripts too.
Code:
<?php
error_reporting(E_ALL ^ E_NOTICE);
class ErrorHandler
{
/** Array of errors */
var $c_errors;
/**
* Constructor - Registers error handling and shutdown functions with PHP
*/
function ErrorHandler ()
{
$this->c_errors = array();
// Call shutdown function
register_shutdown_function(array(&$this, 'onShutdown'));
set_error_handler(array(&$this, 'onError')) ;
}
/**
* Handle shutdown event
*/
function onShutdown ()
{
// Check any errors have been registered
if ( ! $this->hasErrors() )
{
return;
}
// Dont generate errors if it's the DAMN search engine re-indexing everything
if ( substr($_SERVER['HTTP_USER_AGENT'], 0, 11) == 'MnoGoSearch')
{
return;
}
// Display message to user - this will display at the bottom of the page
print('<hr />');
print('<b>Sorry, errors have occured while processing you request</b>');
print('<p>An administrator has been notified, and the problem should be fixed shortly');
// Set the 'From' address, some SMTP servers only allow mail to be sent from specific domains
$l_headers = 'From: ';
$l_message = "";
// Itterate through errors and add them to the list
$i = 0;
foreach ($this->c_errors as $l_error)
{
$i++;
$l_message .= "-- Error $i ---------------------------------------------------\n";
$l_message .= " Type: " . $this->getErrorDescription($l_error['type']) . "\n";
$l_message .= " Time: " . $l_error['time'] . "\n";
$l_message .= " Msg: " . $l_error['message'] . "\n";
$l_message .= " File: " . $l_error['file'] . ":" . $l_error['line'] . "\n";
$l_message .= " Ctx: " . $l_error['context'] . $l_error['context'] . "\n";
}
// Add debug information for Server
$l_message .= "\n\n-- _SERVER: ---------------------------------------------------\n";
$l_message .= print_r($_SERVER, true);
// Add client 'GET' debug information
$l_message .= "\n\n-- _GET: ---------------------------------------------------\n";
$l_message .= print_r($_GET, true);
// Add client 'POST' debug information
$l_message .= "\n\n-- _POST: ---------------------------------------------------\n";
$l_message .= print_r($_POST, true);
// Add client 'SESSION' debug information
$l_message .= "\n\n-- _SESSION: ---------------------------------------------------\n";
$l_message = print_r($_SESSION, true);
// And finally e-mail the report to the administrator
mail ('', $_SERVER['SERVER_NAME'] . ' error report', $l_message, $l_headers);
echo $l_message;
return;
}
/**
* Get a description of the error given it's code
* @param $a_code Error number that represents it (e.g. E_USER_ERROR)
* @return Text string describing the error
*/
function getErrorDescription ($a_code)
{
switch ($a_code)
{
case E_COMPILE_ERROR:
return "Compile Error";
case E_COMPILE_WARNING:
return "Compile Warning";
case E_CORE_ERROR:
return "Core Error";
case E_CORE_WARNING:
return "Core Warning";
case E_ERROR:
return "Error";
case E_WARNING:
return "Warning";
case E_NOTICE:
return "Notice";
case E_PARSE:
return "Parse";
case E_USER_ERROR:
return "Error (User Generated)";
case E_USER_WARNING:
return "Warning (User Generated)";
case E_USER_NOTICE:
return "Notice (User Generated)";
// Unknown!
default:
return "Unknown ($a_code)";
}
}
/**
* Check if there have been any errors registered
* @return true if there have been, false if not
*/
function hasErrors ()
{
if ( count($this->c_errors) )
{
return true;
}
return false;
}
/**
* Handle error event
* @param $errno Error type (e.g. E_USER_ERROR)
* @param $errstr Message that describes the error
* @param $errfile File that the error occured in
* @param $errline Line of that file that the error occured on
* @param $errcontext Context that the error happened within
*/
function onError ($errno, $errstr, $errfile, $errline, $errcontext)
{
// Create error struct
$l_error = array();
$l_error['type'] = $errno;
$l_error['message'] = $errstr;
$l_error['file'] = $errfile;
$l_error['line'] = $errline;
$l_error['context'] = $errcontext;
$l_error['time'] = strftime('%d/%m/%y - %T');
// And just add it to the end
array_push($this->c_errors, $l_error);
}
}
// Register the error handler
// EOF
?>