- Display_errors = Off
- error_reporting = E_all
Copy CodeBy 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
Copy CodeThe 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
Copy CodeRestart Apache and it's all set up. Next, you'll learn how to do the same thing on Apache. 2. 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/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
Copy CodeThis 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 , is not blocked.
- * For now, avoid warnings of e_strict mode
- * (This must is done before function definitions)
- */
- if (defined (' e_strict ')) {
- $old _error_reporting = error_reporting (0);
- if ($old _error_reporting & e_strict) {
- Error_reporting ($old _error_reporting ^ e_strict);
- } else {
- Error_reporting ($old _error_reporting);
- }
- unset ($old _error_reporting);
Copy CodeThe following are common:
Turn off all error reporting;
- error_reporting (0);
Report easy running errors; reporting a simple run error
- Error_reporting (E_error | e_warning | E_parse);
Reporting E_notice can 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 of set in php.ini; all errors are reported but not included E_notice which is also the default setting for PHP.ini
- Error_reporting (e_all ^ e_notice);
Report All PHP errors (bitwise is used in PHP 3); reports all errors
- Error_reporting (E_all);
Same as error_reporting (E_all); ibid.
- Ini_set (' error_reporting ', e_all);
Copy Code |