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.

hakre
  • 193,403
  • 52
  • 435
  • 836
icomrade
  • 1,053
  • 1
  • 9
  • 11
  • 11
    Advice ... Fix the code or the bugs would get better and more difficult to debug – Baba Apr 02 '12 at 20:26
  • 7
    s/Unfortunately/Fortunately – NikiC Apr 02 '12 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 02 '12 at 20:31
  • Just because errors appear in php 5.4 doesn't mean they don't exist in older version, I'm pretty sure that error reporting was beefed up in this release as the developers of php are moving towards a more strict language. – icomrade Apr 02 '12 at 20:36
  • 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 – Jonathan DS Apr 02 '12 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 02 '12 at 22:04
  • 1
    I plan to fix the errors I just don't need a 100mb error log as I already have a copy of all the errors. – icomrade Apr 03 '12 at 00:33
  • 6
    just answer the question people. nobody asked for your expert opinions! – AbiusX Dec 26 '13 at 19:37
  • 1
    Just a note for Googlers, I would recommend turing off warnings in any production environment. – seavers May 07 '14 at 13:18

5 Answers5

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
David Stockton
  • 2,261
  • 1
  • 14
  • 20
  • Thanks for the help, that seemed to work for most of the strict errors. – icomrade Apr 03 '12 at 00:32
  • 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 '12 at 16:44
  • 2
    You could try putting & ~E_DEPRECATED in along with the other parts in error_reporting(). What messages are you seeing? – David Stockton Aug 29 '12 at 07: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 – andrewtweber Feb 28 '13 at 20:58
  • Is there a way to do the same thing for the error_log file as opposed to the PHP file? – Andrew May 13 '14 at 00:52
  • @AndrewSpear What do you mean do the same thing for the error_log file? – David Stockton May 14 '14 at 05:15
  • @david-stockton I find that the .htaccess solution above works for altering the error output on the PHP pages themselves, but doesn't affect the errors appearing in the site's error_log file. (CentOS/cPanel) – Andrew May 14 '14 at 21:23
  • 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. – David Stockton May 15 '14 at 03:51
  • @david-stockton Thanks for the clarification, it could be an issue with my server config, I'll look into it. – Andrew May 15 '14 at 07:41
  • 4
    +1 for answering a simple question with a simple answer without turning into a StackOverflow Smuglord ™. – KatDevsGames May 31 '14 at 17:29
  • Nb. because the error_reporting setting can be set at many levels, it's possible that people reporting "doesn't work" are having their low-level (e.g. apache config or php.ini) settings overridden at application level. e.g. Drupal 7 manages this itself (at /admin/config/development/logging FWIW). Hope that helps other Drupal users at least. – artfulrobot Aug 29 '14 at 10:00
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.

Taras
  • 572
  • 3
  • 15
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
Guzik
  • 194
  • 6
  • 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!!! – Jamie Hutber Aug 15 '14 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.

ux.engineer
  • 10,082
  • 13
  • 67
  • 112
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.

Moon
  • 1
  • 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 '17 at 08:02