Home Backend Development PHP Tutorial PHP basic learning: error handling

PHP basic learning: error handling

May 22, 2018 pm 01:41 PM
php Base Error handling

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

<!-- Error handling -->

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

&lt;?php

    //php错误处理之禁止显示错误(display_errors)

    ini_set(&#39;display_error&#39;, 0);

        

    echo &#39;服务器中display_errors的状态为&#39;.ini_get(&#39;display_errors&#39;);

?&gt;

    

&lt;!-- php错误处理值错误报告级别 --&gt;

&lt;?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;

?&gt;

    

&lt;!-- php错误处理之错误记录日志 --&gt;

&lt;?php

// php.ini中的配置

// log_errors

// log_errors_max_len

// error_log(重点)

    echo ini_get(&#39;log_errors&#39;);

        

    error_log(&quot;无法连接到数据库服务器服务器&quot;);

    error_log(&#39;可以用邮件报告错误,让运维人员半夜

        起床干活&#39;,1,&#39;pig@php.cn&#39;);

    error_log(&quot;我是一个错误哟&quot;,3,&quot;d:/test/my-errors.log&quot;);

?&gt;

&lt;!-- php错误处理之自定义错误处理函数 --&gt;

&lt;?php

    function customError($errno, $errstr,

        $errfile,$errline){

        echo &quot;&lt;b&gt; Custom error:&lt;/b&gt; [$errno] $errstr &lt;br /&gt;&quot;;

        echo &quot;Error on line $errline in $errfile&lt;br/&gt;&quot;;

        echo &quot;Ending Script&quot;;

        exit;

    }

    set_error_handler(&quot;customError&quot;);

        

    $test=2;

    if ($test &gt; 1) {

        trigger_error(&quot;A custom error has been triggered&quot;);

    }

?&gt;

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!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles