function debug_user_handler($errno, $errstr, $errfile, $errline, $errcontext)
{
ob_start();
debug_print_backtrace();
$trace = ob_get_contents();
ob_end_clean();
$data = array(
isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : "",
date("Y-m-d H:i:s"),
"錯誤號{$errno}, 文件:{$errfile} 行號: {$errline}",
$errstr,
$trace);
trigger_error(implode("\n", $data) . '(' . $errno . ')');
}
set_error_handler('debug_user_handler', E_USER_NOTICE|E_USER_WARNING);
function test_handler()
{
$x = mt_rand(0, 100);
echo "x=$x\n";
if ($x > 50) {
trigger_error("x great than 50", E_USER_NOTICE);
} else {
trigger_error("x less than 50", E_USER_WARNING);
}
}
test_handler();