Home > 类库下载 > PHP类库 > body text

php error handling

高洛峰
Release: 2016-10-08 17:42:47
Original
1307 people have browsed it

Error type

Because of the clever setting of the error type integer value, bitwise operators can be used

1 E_ERROR (integer)

Fatal runtime error. This type of error is generally an unrecoverable situation, such as a problem caused by memory allocation.
Causing the script to terminate and no longer continue to run
Example: Calling an undefined function, there is an uncaught exception

2 E_WARNING (integer)

Run-time warning (non-fatal error)
Only a prompt message is given, but the script does not Will terminate the operation.

4 E_PARSE (integer)

Compile time syntax parsing error.
Parse errors are generated only by the parser.
register_shutdown_function cannot capture this error that occurred in this file

8 E_NOTICE (integer)

Runtime notification. Indicates that the script encounters a situation that may appear as an error, but there may also be similar notifications in scripts that can run normally
Example: Using undefined variables

16 E_CORE_ERROR (integer)

During the PHP initialization startup process A fatal error occurred.
This error is similar to E_ERROR, but is generated by the PHP engine core.

32 E_CORE_WARNING (integer)

Warning (non-fatal error) occurred during PHP initialization startup process
Similar to E_WARNING, but generated by the PHP engine core

E_COMPILE_

Compilation related
64 E_COMPILE_ERROR (integer)
Fatal compilation Time error. Similar to E_ERROR, but generated by the Zend script engine. since PHP 4
128 E_COMPILE_WARNING (integer)
Compile time warning (non-fatal error). Similar to E_WARNING, but generated by the Zend scripting engine.

E_USER_

User-generated
256 E_USER_ERROR (integer)
User-generated error message. Similar to E_ERROR, but is generated by the user using the PHP function trigger_error() in the code. since PHP 4
512 E_USER_WARNING (integer)
Warning message generated by the user. Similar to E_WARNING, but is generated by the user using the PHP function trigger_error() in the code. since PHP 4
1024 E_USER_NOTICE (integer)
Notification information generated by the user. Similar to E_NOTICE, but is generated by the user using the PHP function trigger_error() in the code

2048 E_STRICT (integer)

Enables PHP's suggestions for code modifications to ensure the best interoperability and forward progress of the code compatibility.

4096 E_RECOVERABLE_ERROR (integer)

A fatal error that can be caught. It indicates that a potentially dangerous error has occurred, but has not caused the PHP engine to become unstable. If the error is not caught by a user-defined handler (set_error_handler()), it will become an E_ERROR and the script will terminate.

8192 E_DEPRECATED (integer)

Runtime notification.
When enabled, a warning will be given for code that may not work properly in future versions.

16384 E_USER_DEPRECATED (integer)

Warning message generated by the user. Similar to E_DEPRECATED, but is generated by the user using the PHP function trigger_error() in the code.

30719 E_ALL (integer)

E_STRICT All errors and warning letters out of the

Error handling related functions

error_reporting

int error_reporting ([ int $level ] )

Set what kind of PHP errors should be reported

/ / Close all PHP error reporting and return the new error reporting level error_reporting(0); // Report simple running errorserror_reporting(E_ERROR | E_WARNING | E_PARSE);

If no parameters are used, the current error reporting level will be returned

error_get_last

Get the last error that occurred, register_shutdown_function() is often used

array error_get_last (void)

return result

Array(
[type] => 8
[message] => Undefined variable: a [file ] => C:WWWindex.php [line] => 2)

trigger_error

Generate a user-level error/warning/notice message

bool trigger_error ( string $error_msg [, int $error_type = E_USER_NOTICE ]

error_log

Send error information to the error log of the web server, or to a file. If the file does not exist, it will be created

bool error_log ( string $message [, int $message_type = 0 [, string $destination [ , string $extra_headers ]]] )

message_type
Set where errors should be sent
0 message is sent to the PHP system log, using the operating system's logging mechanism or a file, depending on the setting of error_log in php.ini. This is the default option.
1 The message is sent to the email address set by the parameter destination. The fourth parameter extra_headers is only used in this type.
3 The message is sent to the location. destination file. The character message is not treated as a new line by default.
4 message sent directly to SAPI’s log handler

set_error_handler()

Set a user-defined error handling function to handle errors that occur in the script

mixed set_error_handler ( callable $error_handler [, int $error_types = E_ALL | E_STRICT ] )


Error types specified in error_types will bypass the PHP standard error handler unless the callback function returns FALSE. The error_reporting() setting will have no effect and your error handler will continue to be called, it is your responsibility to use die() when needed.

NOTE
The following levels of errors cannot be handled by user-defined functions: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most E_STRICT

error_handler

handler ( int $errorLevel , string $errorMessage [, string $errfile [, int $errline [, array $errcontext ]]] )


errcontext, is an array pointing to the active symbol table when the error occurs. That is, errcontext will contain an array of all variables in the scope where the error was triggered. The user's error handler should not modify the error context.

set_exception_handler

Set a user-defined exception handling function

getMessage(), "n";}set_exception_handler('exception_handler ');throw new Exception('Uncaught Exception');echo "Not Executedn";?>


register_shutdown_function

This function is a function that runs after the script ends (whether it ends normally or ends by exit or error) )

Error configuration in php.ini

Summary of PHP error mechanism

error_reporting = E_ALL // Report error level, what level error_log = /tmp/php_errors.log // Log location of error display in php display_errors = On // Whether to display errors on the output, this output may be a page, It may also be stdoutdisplay_startup_errors = On // Whether to display the error information of the startup process on the page. Remember that there are several Core type errors mentioned above that occur during startup. This is to control whether these errors are displayed on the page. log_errors = On // Whether to record error logs log_errors_max_len = 1024 // Maximum length of error log ignore_repeated_errors = Off // Whether to ignore repeated errors track_errors = Off // Whether to use the global variable $php_errormsg to record the last error xmlrpc_errors = 0 / /Whether to use the XML-RPC error message format to record errors xmlrpc_error_number = 0 // Used as the value of the XML-RPC faultCode element. html_errors = On // Whether to turn the functions and other information in the output into HTML links docref_root = http://manual/en/ // If html_errors is turned on, what is the root path of this link fastcgi.logging = 0 // Whether to turn PHP errors are thrown into fastcgi

PHP defaults to the log and standard output (if it is fpm mode, the standard output is the page)
The parameter of error_reporting is the error level. Indicates what level should trigger an error
display_errors controls whether error information should be displayed on the standard output
log_errors controls whether error information should be recorded in the log
error_log is the location where the error log is displayed

<br/>
Copy after login


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!