Assigning the return value of new by reference is

2019-01-04 02:07发布

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.

标签: php php-5.2
10条回答
何必那么认真
2楼-- · 2019-01-04 02:31

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.
查看更多
地球回转人心会变
3楼-- · 2019-01-04 02:32

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.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-04 02:34

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

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-01-04 02:37

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.

查看更多
女痞
6楼-- · 2019-01-04 02:37

& 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 variables by reference by default.

查看更多
再贱就再见
7楼-- · 2019-01-04 02:43

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

查看更多
登录 后发表回答