这篇文章主要介绍了php自定义错误处理用法,实例分析了php通过自定义函数进行错误处理的技巧,需要的朋友可以参考下
本文实例讲述了php自定义错误处理用法。具体如下:
<?phperror_reporting(e_all);function errhandler($errorno, $errorstr, $errorfile, $errorline){ $display = true; $notify = false; $halt_script = false; $error_msg = "<br>the $errorno error is occurring at $errorline in $errorfile<br>"; switch($errorno) { case e_user_notice: case e_notice: $halt_script = false; $notify = true; $label = "<b>notice</b>"; break; case e_user_warning: case e_warning: $halt_script = false; $notify = true; $label = "<b>warning</b>"; break; case e_user_error: case e_error: $label = "<b>fatal error</b>"; $notify=true; $halt_script = false; break; case e_parse: $label = "<b>parse error</b>"; $notify=true; $halt_script = true; break; default: $label = "<b>unknown error</b>"; break; } if($notify) { $msg = $label . $error_msg; echo $msg; } if($halt_script) exit -1;}$error_handler = set_error_handler("errhandler");echo "<br><h2>using custom error handler</h2><br>";trigger_error("<br>error caused by e_user_notice</br>", e_user_notice);trigger_error("<br>error caused by e_user_warning</br>", e_user_warning);trigger_error("<br>error caused by e_user_error</br>", e_user_error);trigger_error("<br>error caused by e_parse</br>", e_parse);?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php获取本周一的日期实现方法
php两种常用递归删除文件夹的方法
php实现加密与解密的原理与用法
以上就是php自定义函数错误处理的方法的详细内容。