PHP error and exception notes and summary (3) Error-related options in PHP configuration file (php.ini) and setting error levels

Source: Internet
Author: User
Tags php error

"Error-related options in PHP configuration file"

Options Describe
Error_reporting Set the level of error reporting
Display_errors Whether an error is displayed
Log_errors Sets whether to log error messages to logs or Error_log
Error_log Set the file to which the script error will be logged
Log_errors_max_len Set the maximum number of bytes for log_errors
Ignore_repeated_errors Whether to ignore duplicate error messages
Ignore_repeated_source Whether to ignore the source of duplicate error messages
Track_errors If this option is turned on, the last error will be permanently saved in $php_errormsg

error_reporting

For example:

error_reporting E_all

Indicates that the error level is all errors. You can also set all the error levels that are mentioned earlier in the statement.

Note: in PHP 5.4 or later, E_strict is part of the E_all.

These error levels can be used alone or in conjunction with bitwise operators .

"Example" shows all errors, but does not show that the error_reporting in Notice,php.ini should be set to:

error_reporting e_all & ~e_notice

display_error

The development environment needs to be open (display_errors = ON) and the production environment (on-line) needs to be turned off (diaplay_errors = off).

"Set Error Level"

① through PHP configuration file settings (this is the way)

② via error_reporting () function setting (dynamic setting)

"Example 1" gets the bitmask of the current error level

<? PHP Echo error_reporting ();

Output:

30719

(the corresponding error_reporting = E_all)

"Example 2" set error level--Show all errors

<? PHP error_reporting (e_all);

"Example 3" does not display notification-level errors

<? PHP error_reporting (e_all & ~e_notice); Echo $dee;

Output:

Nothing is output.

"Example 4" Masks all errors -when deployed to a line, you can set the error level in this way to prevent information from leaking to the user

<? PHP error_reporting (0); Echo //Fatal level error

Output:

Nothing is output-even the fatal level of error (Fatal level) is unrealistic, but parsing errors (the grammar detection phase) still appear , as in Example 5

"Example 5"

<? PHP error_reporting (0); Echo Dee ()

Output:

$end, expecting ', ' or '; ' in D:\practise\php\Error\error1.php-line 3

"Example 6" shows all errors

<? PHP error_reporting ( -1); Echo Dee ();

Output:

function Dee () in D:\practise\php\Error\error1.php on line 3

③ by Ini_set () function run- time setting

"Example 1" does not show all errors

<? PHP Ini_set (' error_reporting ', 0); Echo Dee ();

Output:

Nothing is output.

Or

<? PHP Ini_set (' Display_errors ', 0); Echo Dee ();

can also achieve the effect of not showing all errors.

"Example 2" shows all errors

<? PHP Ini_set (' error_reporting ',-1); Echo Dee ();

Output:

function Dee () in D:\practise\php\Error\error1.php on line 3

"Common Settings"

In php.ini, you can set the error_reporting as follows to block hints that we think are not errors:

error_reporting e_all & ~e_notice & ~e_strict & ~e_deprecated

Or, before sending the header, all the content is output to the memory buffer (output buffering).

"Attached" ① bitwise operator

②php 5.4 or above is officially recommended to replace MySQL with mysqli

PHP error and exception notes and summary (3) Error-related options in PHP configuration file (php.ini) and setting error levels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.