Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I configure PHP to ignore error_reporting() at runtime?

Tags:

php

I am running an application which is riddled with error_reporting calls, but I'm running PHP 5.5 which has a lot of depreciated warnings. I have configured my php.ini file correctly like this.

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

But all of the error_reporting() calls override it. Is there any way I configire to ignore runtime calls to error_reporting()?

Changing all the error_reporting() calls is a real hassle, especially as the application will need to be regularly updated and I want to avoid running a post install hack script.

I don't want to mention the name of the app, it's VBulletin 5.

like image 860
thomas-peter Avatar asked Oct 25 '13 12:10

thomas-peter


2 Answers

There is an ini-setting disable_functions, which you could use to disable the error_reporting() function. That way the application can not set the error reporting level via this function.

disable_functions = error_reporting

Only internal functions can be disabled using this directive. User-defined functions are unaffected. This directive must be set in php.ini For example, you cannot set this in httpd.conf.

See: http://www.php.net/manual/en/ini.core.php#ini.disable-functions

like image 186
feeela Avatar answered Oct 11 '22 15:10

feeela


If you have control over the webserver configuration you can use php_admin_value to set error_reporting to a value that cannot be overriden.

According to the documentation this cannot be used in a .htaccess file, so you will have to use it on the whole server ... maybe a little too much.

Another possibility would be to use disable_functions to disable error_reporting. Downside would be that you will get a warning every time it is used, but you can get around that:

You can add a section to your php.ini that only affects the specified script:

[PATH=<path>]
error_reporting = 0
disable_functions = "error_reporting"
like image 39
Gerald Schneider Avatar answered Oct 11 '22 13:10

Gerald Schneider