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

PHP 自定义错误拦截

PHP中文网
Release: 2016-05-25 17:00:46
Original
1503 people have browsed it

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);
?>
Copy after login

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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template