Remove warning messages in PHP

2019-01-03 12:30发布

I have some PHP code. When I run it, a warning message appears.

How can I remove/suppress/ignore these warning messages?

10条回答
我只想做你的唯一
2楼-- · 2019-01-03 12:54

If you want to suppress the warnings and some other error types (for example, notices) while displaying all other errors, you can do:

error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
查看更多
SAY GOODBYE
3楼-- · 2019-01-03 12:59

You really should fix whatever's causing the warning, but you can control visibility of errors with error_reporting. To skip warning messages, you could use something like:

error_reporting(E_ERROR | E_PARSE);
查看更多
forever°为你锁心
4楼-- · 2019-01-03 13:00

in Core Php to hide warning message set error_reporting(0) at top of common include file or individual file.

In Wordpress hide Warnings and Notices add following code in wp-config.php file

ini_set('log_errors','On');
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
查看更多
Explosion°爆炸
5楼-- · 2019-01-03 13:03

You could suppress the warning using error_reporting but the much better way is to fix your script in the first place.

If you don't know how, edit your question and show us the line in question and the warning that is displayed.

查看更多
闹够了就滚
6楼-- · 2019-01-03 13:04

If you don't want to show warnings as well as errors use

// Turn off all error reporting
error_reporting(0);

Error Reporting - PHP Manual

查看更多
男人必须洒脱
7楼-- · 2019-01-03 13:10

You can put an @ in front of your function call to suppress all error messages.

@yourFunctionHere();
查看更多
登录 后发表回答