Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't disable PHP errors

So what's going on is I tried

ini_set('display_errors', 'Off');
error_reporting(0);

Right below <?php, but this didn't seem to stop displaying them. So I went to the php.ini and went to display_errors and saw that it was set to Off. But it still showed.

So I went and did phpinfo() and display_errors along with display_startup_errors are both off. Also html_errors is off. I'm not sure if this will help, but it says error_reporting is set to -10241. Any ideas?

like image 523
Idris Avatar asked Oct 01 '22 05:10

Idris


3 Answers

Do not change the value of error reporting to solve the issue. If display_errors is off, errors are not display independently of the error_reporting setting. This way you will not display errors but you can still log them.

The following should work:

ini_set('display_errors', 'Off');

If it doesn't work it could be that your server configuration does not allow you to change settings from PHP scripts. ini_set() returns FALSE on failure. So first of all you should check what value that call is returning. Make sure that ini_set is not listed among disabled PHP functions (disable_functions in php.ini).

If you are asking yourself why errors are still being displayed even if in php.ini the display_errors is Off, you can check the actual value of display_errors during the script execution:

ini_get('display_errors')

Pemember that PHP settings could be changed also in Apache host configuration and in .htaccess files. So check if you have an htacces that enables display_errors. Something like this:

php_flag display_errors on
like image 86
Claudio Venturini Avatar answered Oct 11 '22 02:10

Claudio Venturini


Try to use:

ini_set('display_errors', 0);
ini_set('display_errors', false);
like image 1
Sandeep Kapil Avatar answered Oct 11 '22 03:10

Sandeep Kapil


You don't describe what the errors are, so it's possible that your web server (Apache, nginx, etc) are what's throwing the error and not PHP.

If it is PHP, ensure that you're editing the correct php.ini as identified in your phpinfo.php. Remember that if you edit the php.ini, you will need to restart your PHP process (for example, on some *nix systems: service php-fpm restart. Your exact command may vary.)

If it's off in your php.ini, my guess is that it's being overridden somewhere else -- either later in the script ('grep "ini_set" /path/to/project/*.php' will find it). Also, the PHP Manual states that if the script has fatal errors, it doesn't apply if there are fatal errors:

Although display_errors may be set at runtime (with ini_set()), it won't have any effect if the script has fatal errors. This is because the desired runtime action does not get executed.

like image 1
Sage Avatar answered Oct 11 '22 03:10

Sage