This article introduces the content of PHP error handling and implementation, now share to everyone, there is a need for friends to refer to
1.php error, warning, how exception handling is implemented, those functions are used to handle the corresponding error
PHP exception hints are divided into three categories Error/warning/notice
Error Supplement:
Fatal Error: Fatal errors (script termination run)
E_error//Fatal run error, error unrecoverable, pause execution script
Fatal error during initialization of E_core_error//php Startup
E_compile_error//compile-time fatal error, just like a e_error generated by the Zend scripting engine
E_user_error//Custom error message. Like with PHP function Trigger_error (Error type set to: E_user_error)
E_recoverable_error//Fatal error that can be captured. It indicates that a potentially very dangerous error has occurred, but has not yet caused the PHP engine to be in an unstable state.
Parse Error: Parsing errors at compile time, syntax error (script terminating run)
E_parse//compile-time syntax parsing error
Warning Supplement: Warning Error (only informational, script not terminating)
E_warning//Run-time warning (non-fatal error).
e_core_warning//PHP initialization warning (non-fatal error) occurred during startup.
e_compile_warning//Compile warning
E_user_warning//user-generated warning message
Exception notification supplement: Notification error (only give notification information, script does not terminate running)
E_notice//run-time notifications. Indicates that the script encountered a situation that might appear to be an error.
E_user_notice//user-generated notification information.
PHP Error Handling implementations:
Register_shutdown_function (' funcName ')//parameter is the name of the function that needs to catch the error, but register_shutdown_function can only catch a fatal error at run time and cannot capture execution error when interpreting Because it is executed after the execution of the program (such as a syntax error, which is not captured when the runtime generates an error)
The Set_error_handler (' funcName ')//parameter is the function name of the callback that needs to be captured, and differs from Register_shutdown_function, which is an error that is caught while the function is running
When the target file execution encounters an error, the system will callback the specified function:
Example:
<?phpregister_shutdown_function ("Fatal_handler"), Set_error_handler ("Error_Handler");d efine (' E_FATAL ', E _error | E_user_error | E_core_error | E_compile_error | e_recoverable_error| E_parse); Get fatal errorfunction Fatal_handler () { $error = Error_get_last (); if ($error && ($error ["Type"]=== ($error ["type"] & E_fatal)) { $errno = $error ["type"];// $ Errfile = $error ["file"]; $errline = $error ["line"]; $errstr = $error ["message"]; Error_Handler ($errno, $errstr, $errfile, $errline);} } Get all Errorfunction Error_Handler ($errno, $errstr, $errfile, $errline) { $str =<<<eof "errno": $ errno " errstr": $errstr "errfile": $errfile "errline": $errlineEOF;//Get to the error can be handled by themselves, such as log, alarm and so on echo $str;} Error_get_last () captures the execution error result//error_clear_last () clears the last error message generated//above both can catch all errors, warnings, exceptions, but for performance reasons, it is not recommended to use its catch warning exception
Related recommendations:
Simple analysis of PHP error handling, automatic loading, stack heap memory and running mode
PHP Error Handling Instance method
PHP Error and exception debugging video tutorial resource sharing