96

I'm currently running a site on php 5.4, prior to this I was running my site on 5.3.8. Unfortunately, php 5.4 combines E_ALL and E_STRICT, which means that my previous setting for error_reporting does not work now. My previous value was E_ALL & ~E_NOTICE & ~E_STRICT Should I just enable values one at a time?

I have far too many errors and the files contain too much code for me to fix.

9
  • 11
    Advice ... Fix the code or the bugs would get better and more difficult to debug
    – Baba
    Apr 2, 2012 at 20:26
  • 7
    s/Unfortunately/Fortunately
    – NikiC
    Apr 2, 2012 at 20:30
  • 96
    Thanks for the advice, however I lack the require knowledge to re-write the entire jfusion phpbb3 plugin. thanks for being condescending though.
    – icomrade
    Apr 2, 2012 at 20:31
  • 12
    I agree with our friends that you should try and fix the erros, they might come and bite your ankle, also hidding all errors make it difficult to debug. But i also don't think it's fair to judge the poster for this lonely question, if you never had to write some hideous work around because your client is in the phone hexxing your unborn children you haven't worked with IT long enought Apr 2, 2012 at 20:40
  • 7
    This is a perfectly reasonable question, and yes @icomrade - you are right about the condescension and sarcasm here. It is one of StackOverflow's less attractive traits. That all said, I do recommend you tackle at least some of the warnings you're getting - even if you can't do them all.
    – halfer
    Apr 2, 2012 at 22:04

5 Answers 5

140

As the commenters have stated the best option is to fix the errors, but with limited time or knowledge, that's not always possible. In your php.ini change

error_reporting = E_ALL

to

error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

If you don't have access to the php.ini, you can potentially put this in your .htaccess file:

php_value error_reporting 30711

This is the E_ALL value (32767) and the removing the E_STRICT (2048) and E_NOTICE (8) values.

If you don't have access to the .htaccess file or it's not enabled, you'll probably need to put this at the top of the PHP section of any script that gets loaded from a browser call:

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

One of those should help you be able to use the software. The notices and strict stuff are indicators of problems or potential problems though and you may find some of the code is not working correctly in PHP 5.4.

11
  • 11
    I am using php 5.4.5 and I tried all of the above but I couldn't disable strict notifications :( any other ideas ?
    – ro ko
    Aug 27, 2012 at 16:44
  • 2
    You could try putting & ~E_DEPRECATED in along with the other parts in error_reporting(). What messages are you seeing? Aug 29, 2012 at 7:17
  • 4
    @roko Is it possible your code is overriding this somewhere? I was still seeing strict errors after disabling it in php.ini, then I realized it was only for some websites, the ones using Drupal, where the value was being set in code Feb 28, 2013 at 20:58
  • 1
    @AndrewSpear That's odd. In theory the error_reporting setting should affect the errors that are shown anywhere they are shown. The display_errors setting should affect whether or not you get the errors in the output (in the PHP pages) and the error_log would affect where the errors get written to the log. If display_errors is on then you should see the same errors on the screen as in the log. May 15, 2014 at 3:51
  • 4
    +1 for answering a simple question with a simple answer without turning into a StackOverflow Smuglord ™. May 31, 2014 at 17:29
2

.htaccess php_value is working only if you use PHP Server API as module of Web server Apache. Use IfModule syntax:

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
    php_value error_reporting 30711
</IfModule>

If you use PHP Server API CGI/FastCGI use

ini_set('error_reporting', 30711);

or

error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE);

in your PHP code, or PHP configuration files .user.ini | php.ini modification:

error_reporting = E_ALL & ~E_STRICT & ~E_NOTICE

on your virtual host, server level.

1

It worked for me, when I set error_reporting in two places at same time

somewhere in PHP code

ini_set('error_reporting', 30711);


and in .htaccess file

php_value error_reporting 30711
1
  • Only thing that worked for me without having access to php.ini, another of the above wouldn't work by itself, only returned a 500 error. Both together baby!!! Aug 15, 2014 at 10:53
1

If you would need to disable E_DEPRACATED also, use:

php_value error_reporting 22527

In my case CMS Made Simple was complaining "E_STRICT is enabled in the error_reporting" as well as "E_DEPRECATED is enabled". Adding that one line to .htaccess solved both misconfigurations.

0

Heads up, you might need to restart LAMP, Apache or whatever your using to make this take affect. Racked our brains for a while on this one, seemed to make no affect until services were restarted, presumably because the website was caching.

1
  • Nope. It's because Apache needs to reload the settings for PHP. This is AFAIK only done when the service starts.
    – svin83
    Aug 11, 2017 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.