PHP basic learning: error handling

jacklove
Release: 2023-03-27 11:58:02
Original
1325 people have browsed it

You will encounter many error handling methods in PHP learning. This article explains the related handling methods.

<?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

This article introduces the error handling mechanism. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

Comparative introduction to SESSION and COOKIE under PHP

Understand the method of obtaining the client IP in PHP

Detailed explanation on the use of Session in php

The above is the detailed content of PHP basic learning: 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