Assigning the return value of new by reference is deprecated

José M. Gilgado picture José M. Gilgado · Jul 6, 2009 · Viewed 224.5k times · Source

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.

Answer

Paul Dixon picture Paul Dixon · Jul 6, 2009

In PHP5 this idiom is deprecated

$obj_md =& new MDB2();

You sure you've not missed an ampersand in your sample code? That would generate the warning you state, but it is not required and can be removed.

To see why this idiom was used in PHP4, see this manual page (note that PHP4 is long dead and this link is to an archived version of the relevant page)