PHP uses the Register_shutdown_function function to intercept the fatal error example, FatalError
When we do projects, we occasionally get fatal error because we are not careful. If Display_errors is set to OFF, the user will see a blank page. If set to ON, the fatal error message will appear (of course, the normal person will not do so).
So what can we do to intercept the fatal error in advance and feed it back to the user in our own custom friendly form? There is a function called Register_shutdown_function in PHP that allows us to set up another function that can be called when execution is closed. That is, the function will be called when the execution of our script completes or the Accidental death causes PHP execution to close.
Let's take a look at the following example:
Copy the Code code as follows:
<?php
$flag = false;
function Deal_error () {
Global $flag;
if (! $flag) {
Die ("coarse problem, please try again later");
}
return false;
}
Register_shutdown_function ("Deal_error");
will fail because of a fatal error
$obj = new Notexistclass (); Introduce undefined classes
Require ('./test.php ');
$flag = true;
At the entrance of the program, we set flag to false and finally set to true to indicate that the program is executing properly. If flag is not true at last, the description dies somewhere in the middle, and register_shutdown_function is called to output our custom error results.
If the class above does not define, introduce a nonexistent file (must use require or require_once), etc., it will cause fatal error. Of course, if your program is missing a punctuation or more than a special character, then there is no way.
http://www.bkjia.com/PHPjc/987895.html www.bkjia.com true http://www.bkjia.com/PHPjc/987895.html techarticle using the Register_shutdown_function function in PHP to intercept the fatal error example, FatalError we occasionally have fatal error when doing a project because of an imprudent appearance. If Display_errors is set to ...