Error handling methods in PHP scripts (PHP Practical Manual Reading Notes)

WBOY
Release: 2016-07-29 09:14:31
Original
820 people have browsed it

What information should be output?

In the process of running PHP scripts, a variety of problems may occur, including user-level errors and system-level errors. These errors are useful to developers, but not necessarily to users. Useful (but users still want to see some error descriptive information), so how do we display these error messages?
Our processing method here is: define a switch variable. When this variable is in the "on" state, we output the error message. When the variable is in the "off" state, we ignore the error message. Here we pass a function to achieve this function

<code>define(“DEBUG_MODE”,<span>true</span>);

<span><span>function</span><span>debug_print</span><span>(<span>$message</span>)</span>
{</span><span>if</span>(DEBUG_MODE)
    {
        <span>echo</span><span>$message</span>
    }
}</code>
Copy after login

In this way, we can control the output of information.


Where is the error message output?

When writing PHP scripts, we usually implement a unified error message output page first. When the PHP script runs with an error, we will jump to this error page. So how is this error jump function implemented? , look at the code:

<code><span><span>function</span><span>handle_error</span><span>(<span>$usr_error_message</span>, <span>$system_error_message</span>)</span>
{</span>
    header(<span>"Location:show_error.php?error_message={$usr_error_message}&system_error_message={$system_error_message}"</span>);
}</code>
Copy after login

In this way, we can process the error information in the unified error output page show_error.php file.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the error handling methods of PHP scripts (PHP Practical Manual Reading Notes), including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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