: This article mainly introduces how to handle PHP script errors (PHP practice manual reading notes). If you are interested in PHP tutorials, refer to it. What information should be output?
Various problems may occur when running PHP scripts, including user-level errors and system-level errors, which are useful to developers, then it is not necessarily useful for users (but users still want to see descriptive information about some errors). how can we display these error messages?
Here, we define a switch variable. when this variable is in the "open" status, we will output an error message. when this variable is in the "off" status, we ignore the error message. here we use a function to implement this function.
define(“DEBUG_MODE”,true);functiondebug_print($message){if(DEBUG_MODE) { echo$message }}
In this way, we can control the output of information.
Where is the error message output?
When writing a PHP script, we usually implement a unified error message output page first. when the PHP script fails to run, we will jump to this error page, so how is the function of this error jump implemented? see the code:
functionhandle_error($usr_error_message, $system_error_message){ header("Location:show_error.php?error_message={$usr_error_message}&system_error_message={$system_error_message}");}
In this way, we can process the error information in the show_error.php file on the unified error output page.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the PHP script error handling method (PHP practice manual reading notes), including some content, hope to be helpful to friends who are interested in PHP tutorials.