Custom error reporting can be handled completely bypassing the standard PHP error handler, so you can print error reports in your own format, or change the location where the error report is printed (The standard PHP error report is where an error occurs and appears at the location where it occurred). There are several scenarios where you can consider custom error handling.
★ Can write down the wrong information, in time to find some production environment problems.
★ can be used to mask errors. An error can leak some information to the user and is likely to be a tool for hackers to attack your site.
★ You can do the corresponding processing, put all error reports to the final script output, or error can show jump to the pre-defined error page, provide a better user experience, if necessary, you can also in the custom error handler, according to the situation to terminate the script run.
★ As a debugging tool, sometimes you have to debug something while running the environment, but you don't want to affect the users you're using.
You typically use the Set_error_handler () function to set a user-defined error-handling function that creates a user's own error-handling method during runtime, returns an old error handler, and returns null if it fails. The function has two parameters, where the first parameter is required and a callback function is required to specify the function to run when an error occurs. This callback function must declare 4 parameters, otherwise invalid, in the order of "There is Error", "error message", "Error File" and "Error line number". The second parameter of the Set_error_handler () function is optional, which specifies which error reporting level now displays user-defined errors. The default is "E_all". Examples of custom error handling are as follows:
In this case, all printed error reports are output in their own format, but there is a point where the system directly reports fatal error is not captured, because the system cannot teach you such a big mistake. It is necessary to resolve this error, so the system will terminate the program directly. Using the Set_error_handler () function is a good way to solve the conflict between security and debugging convenience, and you can also take a little thought to make the error prompt more beautiful to match the style of the website. But pay attention to two points.
①e_error, E_parse, E_core_error, e_core_warning, E_compile_error, and e_compile_warning are not handled by this handle, which means they are displayed in the most primitive way. However, these errors are either compiled or the PHP kernel is faulty and will not normally occur.
After ② uses Set_error_handler (), the error_reporting () will fail. That is, all errors (except for the above errors) will be taught to define function handling.
>> This article fixed link: http://php.ncong.com/php_course/wrong/zidingyiwrong.html
>> reprint Please specify: Ntshongwana PHP August 05, 2014 Yuncon PHP Learning tutorial Published