<?php
// sample code for error handling - a custom error handling in php
// http://royads.blogspot.com
ini_set('display_errors', 'Off');
ini_set('log_errors', 'On');
function UserErrorHandler($errno, $errstr, $errfile, $errline)
{
switch ($errno) {
case E_USER_WARNING:
echo "USER WARNING : [$errno] $errstr\n";
break;
case E_USER_NOTICE:
echo "USER NOTICE : [$errno] $errstr\n";
break;
case E_USER_ERROR:
echo "USER ERROR : [$errno] $errstr\n";
echo "There is a fatal error on line no $errline in script $errfile\n";
echo PHP_VERSION . " on (" . PHP_OS . ")\n";
echo "Execution ends\n";
exit();
break;
default:
echo "Unknown error types: [$errno] $errstr\n";
break;
}
/* you can send email to admin or any other logging system */
return true;
}
set_error_handler("UserErrorHandler",E_ALL);
$x=0;
$y=1;
// division by 0 error
echo $y/$x;
echo "\n\n";
// lets c user error
if(0===$x)
trigger_error('X cant be 0',E_USER_ERROR);
?>