Questions & Answers

Turn off deprecated errors in PHP 5.3

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.

2023-01-19 00:15:10
Isn't 3.3.1 the current up to date version of wordpress?
2023-01-19 00:15:10
he seems to like an old php with old wordpress
Answers(10) :

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

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);


error_reporting(E_ALL ^ E_DEPRECATED);
2023-01-19 00:15:10
Thank you Robus, Will this kill any php error reporting as well?
2023-01-19 00:15:10
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.
2023-01-19 00:15:10
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 :-(
2023-01-19 00:15:10
@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
2023-01-19 00:15:10
Doesn't work. Is it overwritten somewhere? Where do you put this?
2023-01-19 00:15:10
what's the difference between E_ALL ^ E_DEPRECATED and the E_ALL & ~E_DEPRECATED syntax ?
2023-01-19 00:15:10
@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.
2023-01-19 00:15:10
@csabinho thx for clarifying that

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);
2023-01-19 00:15:10
It's much better to add this to wp-config.php. It's intended to be edited with configuration settings.

I needed to adapt this to

error_reporting = E_ALL & ~E_DEPRECATED

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...

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.

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.

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.

2023-01-19 00:15:10
this was the only solution that works

I tend to use this method

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

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

2023-01-19 00:15:10
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.
2023-01-19 00:15:10
Understand. Every case is different.
2023-01-19 00:15:10
This is nevertheless the best answer. It is the only one that directly answers the question: only disable E_DEPRECATED, without any side effects.

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:


2023-01-19 00:15:10
don't do that, that hides all error messages, not only for depreciations.

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 );