José M. Gilgado José M. Gilgado - 3 months ago 8
PHP Question

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.

Answer

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.

Comments