无详细内容 无 ?php/** * 异常处理 * @return void */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['REQUE
<?php
/**
* 异常处理
* @return void
*/
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();
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号