欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP 自定义错误拦截

程序员文章站 2022-05-05 15:01:37
...
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('error_handler');
 
test(a);
?>

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