[php] Assigning the return value of new by reference is deprecated

I've just got an error.

When I try to assign an object like this:

$obj_md = new MDB2();

The error I get is "Assigning the return value of new by reference is deprecated". Actually I've been looking for a solution but the only one I've seen is just turn down the politicy of php.ini (error_reporting). I've tried it too, but it didn't work.

It's so confusing..I hope you could help me. Thanks in advance.

This question is related to php php-5.2

The answer is


I had the same problem. I already had the '&' and still it was giving the same warning. I'm using PHP 5.3 with WAMP and all i did was REMOVE '&' sign and the warning was gone.

$obj= new stdClass();  //Without '&' sign.

Nitin is correct - the issue is actually in the MDB2 code.

According to Replacement for PEAR: MDB2 on PHP 5.3 you can update to the SVN version of MDB2 for a version which is PHP5.3 compatible.

As that answer was given in March 2010, and http://pear.php.net/package/MDB2/ shows a release some months later, I expect the current version of MDB2 will solve the issue also.


I recently moved a site using SimplePie (http://simplepie.org/) from a server that was using PHP 5.2.17 to one that is using PHP 5.3.2. It was after this move that I began receiving a list of error messages such as this one:

Deprecated: Assigning the return value of new by reference is deprecated in .../php/simplepie.inc on line 738

After reviewing several discussions of this issue, I cleared things up by replacing all the instances of =& new with = new in the simplepie.inc file.

I'm not experienced enough to know if this will work in all instances where these error messages are received but it worked in this particular case and it may be worth trying.


Perhaps the constructor of MDB2 has some code that uses a $variable =& new ClassName();


just remove new in the $obj_md =& new MDB2();


C:\wamp\www\..\libraries\pattemplate

1.ini_set('display_errors', 0);

$this->_modules[$moduleType][$sig]  =&new $moduleClass;   wrong

$this->_modules[$moduleType][$sig]  =new $moduleClass;   Right

& is used in PHP to pass an object to a method / assign a new object to a variable by reference. It is deprecated in PHP 5 because PHP 5 passes all objects by reference by default.


It happened because of PHP 5.3 , which comes in WAMP 2.0i package and not Joomla.

You have two choices to fix it,

either use WAMP 2h (previous version) or download PHP 5.2.9-2 addon from WAMP website.


Upgrade your pear/MDB2 from console:

# pear upgrade MDB2-beta
# pear upgrade MDB2_Driver_Mysql-beta

Problem solved at version 2.5.0b3