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 13:11

To suppress warnings while leaving all other error reporting enabled:

error_reporting(E_ALL ^ E_WARNING); 
查看更多
\"骚年 ilove
3楼-- · 2019-01-03 13:14

I do it as follows in my php.ini:

error_reporting = E_ALL & ~E_WARNING  & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

This logs only fatal errors and no warnings.

查看更多
4楼-- · 2019-01-03 13:16

Not exactly answering the question, but I think this is a better compromise in some situations:

I had a warning message as a result of a printf() statement in a third-party library. I knew exactly what the cause was - a temporary work-around while the third-party fixed their code. I agree that warnings should not be suppressed, but I could not demonstrate my work to a client with the warning message popping up on screen. My solution:

printf('<div style="display:none">');
    ...Third-party stuff here...
printf('</div>');

Warning was still in page source as a reminder to me, but invisible to the client.

查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-03 13:18

I think that better solution is configuration of .htaccess In that way you dont have to alter code of application. Here are directives for Apache2

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
查看更多
登录 后发表回答