thomas-peter
thomas-peter

Reputation: 7944

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

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.

Upvotes: 11

Views: 1845

Answers (2)

Gerald Schneider
Gerald Schneider

Reputation: 17797

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"

Upvotes: 5

feeela
feeela

Reputation: 29932

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

Upvotes: 10

Related Questions