Stumbler
Stumbler

Reputation: 2146

Turn off error reporting in PHP (Master vs local value)

I have tried turning off error reporting in my code using

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

and also by editing both the .htaccess files in both the root and frontend folders (separately).

Editing the .htaccess to include code such as

php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
php_value error_log /home/path/logs/PHP_errors.log
php_value error_reporting -1
php_value log_errors_max_len 0

Produces a 500 error. Editing the .htaccess is otherwise allowed on this server,

The description of the error is

Invalid command 'php_flag', perhaps misspelled or defined by a module not included in the server configuration

So it apparently doesn't like me adding this type of code in the .htaccess due to some underlying configuration.

Looking at phpinfo() it says that the local value of error reporting is "off" (presumably caused by error_reporting(0)), but crucially the master value is "on".

How might the master value be overwritten, or the local value actually win out? (errors are still reported when local value is "off")

Upvotes: 0

Views: 1737

Answers (1)

Nadir Latif
Nadir Latif

Reputation: 3773

You should not need the Php directives in .htaccess file.

The master value for a Php configuration is the value before any Php code is executed. The local value is the value of the configuration at the time the phpinfo() function is called. See this link: What is the difference between local value and master value

The following code added at the top of your Php file should turn of error reporting:

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

Upvotes: 1

Related Questions