tags:

views:

14071

answers:

5

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

+4  A: 

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.

Paul Dixon
No, I don't have that ampersand. :(
Polar Geek
May be I had to say I'm using Jpgraph. I don't really know if that matters..
Polar Geek
manual page link is dead
Joseph Kingry
Thanks, the php4 parts of the manual have been rearranged, have corrected the link.
Paul Dixon
It also appears that the MDB2 source code itself uses this deprecated assignment method; several people (including myself) get the aforementioned "deprecated" warning message on PHP 5.3 whenever an MDB2 object is created. It looks like the MDB2 team has a bug for it: http://pear.php.net/bugs/bug.php?id=16508
Clint Harris
+1  A: 

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

Nitin
A: 

You saved me! thanks

A: 

why do we use & sign before a var in php. i know this method is deprecated but i would like to know whats its purpose??? thanks

ahmu83
A: 

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

jeshurun