PHP after installation, will be in the php.ini file set errors, reminders, warnings and other ways to appear, so that we can debug PHP program in time to understand the problem of the program. Then, sometimes we do not need reminders, warnings and other content, such as when we use PHP5.5 (or higher), with the MySQL development environment, using the older MySQL connection mode, PHP will prompt: Please use the latest MySQL connection mode, When you use its read database content as JSON format (or other) to return to the foreground, there is often an error in the content
How to block this error, the method has the following:
1. Add a masking Error alert on a page that may (or has been) a reminder, or error, or warning:
Error_reporting (e_all ^ e_deprecated);
In this release of php5. 5, old-fashioned MySQL connection methods are not recommended
But speedphp still follow the old-fashioned connection method, then PHP will report e_deprecated hint, at this time to turn off the prompt is OK, you can also
PHP is placed in deployment mode (non-development mode), but the best solution is to use the latest speedphp
General can also use the following content to solve some notice waring and other issues
Ini_set ("Display_errors", 0);
Error_reporting (e_all ^ e_notice);
Error_reporting (e_all ^ e_warning);
2, open the php.ini file, find the relevant settings (such as), change on to OFF, you can mask the error (this method is not recommended):
Sometimes modify the php.ini dispaly_errors or not, then refer to the following method:
Modify PHP.ini, change display_errors = on to Display_errors = OFF, the result is still not working. Baidu, the original also in the php-fpm.conf set.
Open php-fpm.conf, find:
<value name= "Php_defines" >
</value><value name= "Sendmail_path" >/usr/sbin/sendmail-t-i</value>
<value name= "Display_errors" >0</value>
Change the value from 1 to 0.
3, this method is very suitable for those projects have decided to adopt some kind of certain will cause a reminder or warning way, one trick shielding, once and for all:
First refer to 2, find the relevant dispaly_errors position, change Off to On
Then find this location, modify the level you need to error, or do not need to error the level
The following error levels are referenced:
定义和用法:
error_reporting() 设置 PHP 的报错级别并返回当前级别。
函数语法:
error_reporting(report_level)
如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值:
值 常量 描述
1 E_ERROR 致命的运行错误。错误无法恢复,暂停执行脚本。
2 E_WARNING 运行时警告(非致命性错误)。非致命的运行错误,脚本执行不会停止。
4 E_PARSE 编译时解析错误。解析错误只由分析器产生。
8 E_NOTICE 运行时提醒(这些经常是你代码中的bug引起的,也可能是有意的行为造成的。)
16 E_CORE_ERROR PHP启动时初始化过程中的致命错误。
32 E_CORE_WARNING PHP启动时初始化过程中的警告(非致命性错)。
64 E_COMPILE_ERROR 编译时致命性错。这就像由Zend脚本引擎生成了一个E_ERROR。
128 E_COMPILE_WARNING 编译时警告(非致命性错)。这就像由Zend脚本引擎生成了一个E_WARNING警告。
256 E_USER_ERROR 用户自定义的错误消息。这就像由使用PHP函数trigger_error(程序员设置E_ERROR)
512 E_USER_WARNING 用户自定义的警告消息。这就像由使用PHP函数trigger_error(程序员设定的一个E_WARNING警告)
1024 E_USER_NOTICE 用户自定义的提醒消息。这就像一个由使用PHP函数trigger_error(程序员一个E_NOTICE集)
2048 E_STRICT 编码标准化警告。允许PHP建议如何修改代码以确保最佳的互操作性向前兼容性。
4096 E_RECOVERABLE_ERROR 开捕致命错误。这就像一个E_ERROR,但可以通过用户定义的处理捕获(又见set_error_handler())
8191 E_ALL 所有的错误和警告(不包括 E_STRICT) (E_STRICT will be part of E_ALL as of PHP 6.0)
Example:
Any number of the above options can be connected (with OR or |) using "or" to report all required levels of errors.
For example, the following code turns off user-defined errors and warnings, performs certain actions, and then reverts to the original error level:
<?php
//禁用错误报告
error_reporting
(0);
//报告运行时错误
error_reporting
(E_ERROR | E_WARNING | E_PARSE);
//报告所有错误
error_reporting
(E_ALL);
?>
?
Solve problems such as PHP display warning and notice