PHP Error level settings

Source: Internet
Author: User
Tags configuration settings php error

You can set the server-to-error alarm level in php.ini. By default, PHP will report all errors except for notifications.
Error reporting levels are set by a number of predefined constants,
Grammar
int error_reporting ([int level])
1 e_error report fatal error at runtime 2 e_warning report non-fatal error running 4 E_PA RSE Report parsing error 8 E_notice report Notice, notice that the thing that is being done may be wrong. E_core_error report PHP engine failed to start         _core_warning report PHP engine startup non-fatal error E_COMPILE_ERROR report compilation error e_compile_warning report a non-fatal error that occurs at compile time 256        E_user_error Report User-triggered Error e_user_warning report user-triggered Warning E_user_notice report user-triggered notification 2047 E_all reports all errors and warnings 2048 e_strict reports disapproval of usage and non-recommended behavior 

In the php.ini file, the default report is any error except the notification, which is set by the following statement:
   
error_reporting = E_all & ~ (E_notice)
< Span style= "color: #525252; font-family:arial,helvetica,simsun,u5b8bu4f53; font-size:14px; line-height:25px; " >
 
   error_reporting = E_all & ~ (E_notice) & ~ (e_warning)
In the php.ini file, there are several settings related to errors:
(1) error_reporting, setting the error level
(2) Display_errors, whether to display error report, set to on then open, set to off to turn off all error prompts
(3) Log_errors, the default setting is off, whether to log error logs;
(4 Track_errors, which is set to off by default, can help resolve errors in your code, rather than having PHP provide its default functionality.
< BR style= "LINE-HEIGHT:25PX; Color: #525252; font-family:arial,helvetica,simsun,u5b8bu4f53; font-size:14px; " > Online collection
E_notice indicates that the general situation is not recorded and is only used if the program has an error condition, such as attempting to access a nonexistent variable, or calling stat () to view files that do not exist. E_warning are usually displayed, but do not interrupt the execution of the program. This is very effective for debugging. For example: Call Ereg () with a problematic regular representation. The e_error is usually displayed, and the program execution is interrupted. This mask cannot be traced to a memory configuration or other error. E_parse parse the error from the syntax. E_core_error is similar to E_error, but does not include errors caused by PHP core. E_core_warning similar to e_warning, but does not include PHP core error warnings.

Error reporting for PHP
There are many configuration settings in the php.ini file. You should have your own php.ini file set up and put it in the appropriate directory, as shown in the documentation for installing PHP and Apache 2 on Linux. When debugging a PHP application, you should know two configuration variables. The following are the two variables and their default values:
Display_errors = Off
error_reporting = E_all
By searching for them in the php.ini file, you can find the current default values for both variables. The purpose of the display_errors variable is obvious-it tells PHP if it shows an error. The default value is OFF. However, to make the development process easier, please set this value to on:
Display_errors = On
The default value for the error_reporting variable is e_all. This setting shows all the information from bad coding practices to harmless prompts to errors. E_all is a bit too thin for the development process because it shows hints on the screen for small things (such as uninitialized variables), which can mess up the browser's output. I just want to see errors and bad coding practices, but don't want to see harmless hints. Therefore, replace the default value of error_reporting with the following values:
error_reporting = E_all & ~e_notice
Restart Apache and it's all set up. Next, you'll learn how to do the same thing on Apache.
Error reporting on the server
Depending on what Apache is doing, opening an error report in PHP may not work because there may be multiple versions of PHP on your computer. It is sometimes difficult to tell which PHP version Apache is using because Apache can only view one php.ini file. It is a security issue to not know which php.ini file Apache is using to configure itself. However, there is a way to configure PHP variables in Apache to ensure that the correct level of error is set.
Also, it is best to know how to set these configuration variables on the server side to veto or preempt php.ini files, providing a higher level of security.
When you configure Apache, you should have been exposed to the basic configuration in the http.conf file in <apache2-install-dir>/conf/httpd.conf.
To do what has already been done in the php.ini file, add the following lines to httpd.conf, overwriting any php.ini files:
Php_flag display_errors on
Php_value error_reporting 2039
This overrides the flags already set for display_errors in the php.ini file, as well as the value of error_reporting. A value of 2039 represents E_all & ~e_notice. If you prefer to use E_all, set the value to 2047. Again, you'll restart Apache.
Next, you will test the error report on the server.

About error_reporting () This function, it can be blocked to some error message, but the PHP core caused by the error, is not blocked, because the PHP core error will directly lead to PHP file compilation failure, because the writing format is not written according to the Code rules of PHP errors caused by , it can't be blocked.

The following are common:

Turn off all error reporting; Turn off all errors error_reporting (0);//report simple running errors; reports a trivial run error error_reporting (e_ ERROR | e_warning | E_parse);//Reporting e_notice can be good too (to report uninitialized//variables or catch variable name misspellings ...) ; Includes spelling errors that report some uninitialized variables or catch variable names error_reporting (E_error | e_warning | E_parse | E_notice);//Report all errors except e_notice//This is the default value set in php.ini; reports all errors but does not include E_noticeerror_reporti Ng (e_all ^ e_notice);//Report All PHP errors (bitwise-BE-be-used in PHP 3); Reporting all Errors error_reporting (e_all);//Same as E Rror_reporting (E_all); ibid. ini_set (' error_reporting ', e_all);

PHP Error level settings

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.