不建议通过引用分配new的返回值 [英] Assigning the return value of new by reference is deprecated

查看:45
本文介绍了不建议通过引用分配new的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚遇到一个错误.

当我尝试分配这样的对象时:

When I try to assign an object like this:

$obj_md = new MDB2();

我得到的错误是不赞成通过引用分配new的返回值".实际上,我一直在寻找解决方案,但是我唯一看到的就是拒绝php.ini的政策(error_reporting).我也尝试过,但是没有用.

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.

推荐答案

在PHP5中,不赞成使用这种习惯用法

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.

要了解为什么在PHP4中使用此惯用语,请参见

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)

这篇关于不建议通过引用分配new的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆