164

My server is running PHP 5.3 and my WordPress install is spitting these errors out on me, causing my session_start() to break.

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 647

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 662

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 669

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 676

Deprecated: Assigning the return value of new by reference is deprecated in /home//public_html/hub/wp-settings.php on line 712

This is annoying, but I do not want to turn off on screen error reporting. How do I disable these bothersome deprecated warnings?

I am running WordPress 2.9.2.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
atwellpub
  • 5,660
  • 11
  • 38
  • 52

10 Answers10

260

You can do it in code by calling the following functions.

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

or

error_reporting(E_ALL ^ E_DEPRECATED);
Toby Allen
  • 10,997
  • 11
  • 73
  • 124
Robus
  • 8,067
  • 5
  • 47
  • 67
  • Thank you Robus, Will this kill any php error reporting as well? – atwellpub May 10 '10 at 15:16
  • 8
    Nope, the first one basically tells php to show ERROR/WARNING/PARSE/NOTICE errors, the second one tells php to show all but DEPRECATED errors. – Robus May 10 '10 at 15:17
  • 1
    Using PHP 5.5.9 on Ubuntu "error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT" Have no effect.... but, in my example, "@mysql_connect();" do the trick :-( – molokoloco Feb 04 '16 at 14:40
  • 2
    @molokoloco you did it wrong twice. First you did not fix a thing. You just silenced it. 2nd, you still using `mysql` which is deprecated. You should at least switch to `mysqli` – Marcin Orlowski Mar 19 '16 at 02:19
  • Doesn't work. Is it overwritten somewhere? Where do you put this? – Alex Apr 12 '17 at 19:12
  • what's the difference between `E_ALL ^ E_DEPRECATED` and the `E_ALL & ~E_DEPRECATED` syntax ? – beppe9000 Jun 22 '22 at 12:57
  • @beppe9000 Both remove the `E_DEPRECATED`-bit from the bit mask. The first by XOR-ing the value, the second by AND-ing the opposite of the value. – csabinho Aug 04 '22 at 08:16
  • @csabinho thx for clarifying that – beppe9000 Aug 06 '22 at 18:52
34

To only get those errors that cause the application to stop working, use:

error_reporting(E_ALL ^ (E_NOTICE | E_WARNING | E_DEPRECATED));

This will stop showing notices, warnings, and deprecated errors.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
codefreak
  • 6,950
  • 3
  • 42
  • 51
25

I needed to adapt this to

error_reporting = E_ALL & ~E_DEPRECATED
Simon H
  • 20,332
  • 14
  • 71
  • 128
16

You have to edit the PHP configuration file. Find the line

error_reporting = E_ALL

and replace it with:

error_reporting = E_ALL ^ E_DEPRECATED

If you don't have access to the configuration file you can add this line to the PHP WordPress file (maybe headers.php):

error_reporting(E_ALL ^ E_DEPRECATED);
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kreker
  • 2,438
  • 3
  • 23
  • 27
  • It's much better to add this to `wp-config.php`. It's intended to be edited with configuration settings. – Nilpo Mar 19 '17 at 00:12
14

I just faced a similar problem where a SEO plugin issued a big number of warnings making my blog disk use exceed the plan limit.

I found out that you must include the error_reporting command after the wp-settings.php require in the wp-config.php file:

   require_once( ABSPATH .'wp-settings.php' );
   error_reporting( E_ALL ^ ( E_NOTICE | E_WARNING | E_DEPRECATED ) );

by doing this no more warnings, notices nor deprecated lines are appended to your error log file!

Tested on WordPress 3.8 but I guess it works for every installation.

Camaleo
  • 1,180
  • 14
  • 14
12

All the previous answers are correct. Since no one have hinted out how to turn off all errors in PHP, I would like to mention it here:

error_reporting(0); // Turn off warning, deprecated,
                    // notice everything except error

Somebody might find it useful...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sudip
  • 2,781
  • 1
  • 29
  • 41
11

In file wp-config.php you can find constant WP_DEBUG. Make sure it is set to false.

define('WP_DEBUG', false);

This is for WordPress 3.x.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Audrius
  • 127
  • 1
  • 2
6

I tend to use this method

$errorlevel=error_reporting();
$errorlevel=error_reporting($errorlevel & ~E_DEPRECATED);

In this way I do not turn off accidentally something I need

realtebo
  • 23,922
  • 37
  • 112
  • 189
  • 1
    That gives you less control. You're assuming that whatever is currently configured is correct. Better to set it directly as needed so that you don't get overlapping configurations. – Nilpo Mar 19 '17 at 00:13
  • 1
    Understand. Every case is different. – realtebo Mar 19 '17 at 16:47
  • 2
    This is nevertheless the best answer. It is the only one that directly answers the question: only disable E_DEPRECATED, without any side effects. – Sygmoral Jan 12 '20 at 15:01
  • 1
    In fact it should be $errorlevel=error_reporting(); error_reporting($errorlevel & ~E_DEPRECATED); but the idea is the best solution. – cootje Apr 01 '23 at 15:22
  • @cootje: you're right, the 2nd assignment isn't strictly needed; I've the habit to save in vars new config when changed (and I save old value in a $_old var of course to be able to restore in a 2nd moment if needed) – realtebo Apr 02 '23 at 10:08
1

If PHP warnings are breaking things in WordPress, but you still want to know what the warnings are, you can disable displaying PHP errors/warnings and only send them to the log file:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'WP_DEBUG_LOG', true );
Gavin
  • 7,544
  • 4
  • 52
  • 72
-3

this error occur when you change your php version: it's very simple to suppress this error message

To suppress the DEPRECATED Error message, just add below code into your index.php file:

init_set('display_errors',False);