首页 >php教程 >PHP源码 >PHP 自定义错误拦截

PHP 自定义错误拦截

PHP中文网
PHP中文网原创
2016-05-25 17:00:461507浏览

PHP 自定义错误拦截

<?php
 
function error_handler($errno, $errstr, $errfile, $errline, $errcontext)
{ 
 
    //$errfile=str_replace(getcwd(),"",$errfile); 
    //$errstr=str_replace(getcwd(),"",$errstr); 
     
    switch ($errno) {  
                case E_USER_ERROR:  
            echo "<b>USER_ERROR</b> <br />";  
            echo "PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />";  
            exit(1);  
            break;  
        case E_USER_WARNING:  
            echo "<b>USER_WARNING</b> <br />";  
             break;  
        case E_USER_NOTICE:  
             echo "<b>USER_NOTICE</b> <br />";  
             break;  
         case E_NOTICE:  
             echo "<b>NOTICE</b> <br />";  
             break;  
         case E_WARNING:  
             echo "<b>WARNING</b> <br />";  
             break;  
         case E_RECOVERABLE_ERROR:  
             echo "<b>RECOVERABLE_ERROR</b> <br />";  
             break;  
         case E_ALL:  
             echo "<b>ALL</b> <br />";  
             break;  
         default:  
            echo "<b>Unknown Error Type</b> <br />";  
            break;  
    }
     
    echo "<b>Error level:</b> [$errno]<br /> ";
    echo "<b>Error message:</b> $errstr<br />";
    echo "<b>Error line:</b> [$errline] <br />";
    echo "<b>Error where:</b> $errfile<br />";
     
}
 
set_error_handler(&#39;error_handler&#39;);
 
test(a);
?>

 以上就是PHP 自定义错误拦截的内容,更多相关内容请关注PHP中文网(www.php.cn)! 


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn