This article introduces in detail a summary of some methods for turning on and off error prompts in PHP, error_reporting, and error reporting PHP error_reporting (E_ALL ^ E_NOTICE). Friends in need can refer to it.
Example:
In the Windows environment: a program that originally ran normally in php4.3.0, why are there many errors reported in 4.3.1? The general prompt is: Notice: Undefined varialbe: variable name.
For example, the following code:
The code is as follows | Copy code | ||||
if (!$tmp_i) {
} |
It runs normally in 4.3.0, but when it runs in 4.3.1, it will prompt Notice:Undefined varialbe:tmp_i
The problem is as follows:
1. Where is the problem?
3. Without changing the code, how to modify the settings in php.ini so that the original program in 4.3.0 can run normally in the 4.3.1 environment without this error prompt.
Solution:Open the php.ini file in the PHP installation directory
Note: If you have Copy the PHP.ini file to the windows directory, then you must also change display_errors = On in c:windows/php.ini to display_errors = off
. Second method to output script error prompts as log files:
Open the php.ini file in the PHP installation directory
Find log_errors = off and change it to log_errors = on
Find error_log = filename and change it to error_log="D:PHPerrlogphp_error.log" (the directory here And the file name D:PHPerrlogphp_error.log (whatever you choose)
In addition, php_error .log must have at least the modify and write permissions of USER, otherwise the error log cannot be output.
About the error_reporting() function:
error_reporting() sets the error level of PHP and returns the current level.
; Error reporting is bitwise. Or add up the numbers to get the desired error reporting level.
; E_ALL - all errors and warnings
; E_ERROR - fatal runtime errors
; E_WARNING - runtime warnings (non-fatal errors)
; E_PARSE - compile-time parsing errors
; E_NOTICE - runtime alerts (These are often caused by bugs in your code, or may be caused by intentional behavior. (eg: using an uninitialized variable based on the fact that it is automatically initialized to an empty string. variable)
; E_CORE_ERROR - fatal error that occurs during the initialization process of PHP startup
; E_CORE_WARNING - warning (non-fatal error) that occurs during the initialization process of PHP startup
; E_COMPILE_ERROR - compile time Fatal error
; E_COMPILE_WARNING - compile-time warning (non-fatal error)
; E_USER_ERROR - user-generated error message
; E_USER_NOTICE - user-generated reminder Message
Usage:
error_reporting(0);//Disable error reporting
error_reporting(E_ALL ^ E_NOTICE);//Display all error messages except E_NOTICE
error_reporting(E_ERROR | E_WARNING | E_PARSE);//Display runtime errors, which has the same effect as error_reporting(E_ALL ^ E_NOTICE);. E_ALL);//Show all errors
Can I turn off PHP’s error prompts? I don’t want others to see the errors in my program.
代码如下 | 复制代码 |
error_reporting(E_ALL^E_NOTICE^E_WARNING); |
Can turn off all notice and warning level errors.
Put this statement in the function include file of your script, usually config.php or conn.php to control the output.
代码如下 | 复制代码 |
//禁用错误报告 error_reporting(0); //报告运行时错误 error_reporting(E_ERROR | E_WARNING | E_PARSE); //报告所有错误 error_reporting(E_ALL); ?> |