PHP basics six error handling

不言
Release: 2023-03-24 16:30:01
Original
1237 people have browsed it

The content of this article is about error handling of PHP Basics Six, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

<!-- 错误处理 -->
<?php
    //php错误处理之禁止显示错误(display_errors)
    ini_set(&#39;display_error&#39;, 0);
    
    echo &#39;服务器中display_errors的状态为&#39;.ini_get(&#39;display_errors&#39;);
?>

<!-- php错误处理值错误报告级别 -->
<?php
//     E_ERROR 
//     E_WARNING 
//     E_NOTICE
//     E_PARSE
//     E_ALL
//     E_STRICT
//     E_DEPRECATED
error_reporting();
    @$fp = fopen(&#39;adsaf.txt&#39;, &#39;r&#39;);
    echo 1;
?>

<!-- php错误处理之错误记录日志 -->
<?php
// php.ini中的配置
// log_errors
// log_errors_max_len
// error_log(重点)
    echo ini_get(&#39;log_errors&#39;);
    
    error_log("无法连接到数据库服务器服务器");
    error_log(&#39;可以用邮件报告错误,让运维人员半夜
        起床干活&#39;,1,&#39;pig@php.cn&#39;);
    error_log("我是一个错误哟",3,"d:/test/my-errors.log");
?>

<!-- php错误处理之自定义错误处理函数 -->
<?php
    function customError($errno, $errstr,
        $errfile,$errline){
        echo "<b> Custom error:</b> [$errno] $errstr <br />";
        echo "Error on line $errline in $errfile<br/>";
        echo "Ending Script";
        exit;
    }
    set_error_handler("customError");
    
    $test=2;
    if ($test > 1) {
        trigger_error("A custom error has been triggered");
    }
?>
Copy after login

Related recommendations:

php basic five image processing


The above is the detailed content of PHP basics six error handling. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!