PHP 如何处理不推荐使用的函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6822446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:23:02  来源:igfitidea点击:

What does PHP do with deprecated functions?

phpdeprecated

提问by James Lin

Getting these errors "Deprecated: Assigning the return value of new by reference is deprecated..."

收到这些错误“已弃用:不推荐使用引用分配 new 的返回值...”

While I know what deprecated function means, but I am not very clear that what PHP does to them? Still execute them as usual? So at this point for this function, does PHP silently assign memory location for the variable or still using reference pointer?

虽然我知道不推荐使用的函数是什么意思,但我不太清楚 PHP 对它们做了什么?仍然像往常一样执行它们吗?那么此时对于这个函数,PHP 是默默地为变量分配内存位置还是仍然使用引用指针?

EDIT- thanks for the answers, I asked this question because we are using adodb_liteand the library has not corrected error.

编辑- 感谢您的回答,我问这个问题是因为我们正在使用adodb_lite并且图书馆没有纠正错误。

回答by hakre

Deperecated functions still exist and you get the warning. So they work as expected. However in a future version they might disappear.

过时的功能仍然存在,您会收到警告。所以他们按预期工作。但是在未来的版本中,它们可能会消失。

That's the same for other deprecated language features which you sometimes get notices about. It's a way to signal changes to users which have code based on an older PHP version.

对于您有时会收到通知的其他已弃用的语言功能,情况也是如此。这是一种向拥有基于旧 PHP 版本代码的用户发出更改信号的方法。

Normally the deprecated features get removed after some time, but it's not predictable how long this takes. I know of at least one case where a once deprecated feature was un-deprecated later on. However, I think that's exceptional.

通常,已弃用的功能会在一段时间后删除,但无法预测这需要多长时间。我知道至少有一种情况,曾经被弃用的功能后来被取消了。不过,我认为这是例外。

So if you see these warnings, update the code. Most often the PHP documentation has more information why something has been deprecated and what to do. Most often it's an improvement (e.g. in security), so you really should deal with these warnings if you care about the code.

因此,如果您看到这些警告,请更新代码。大多数情况下,PHP 文档包含更多信息,为什么某些内容已被弃用以及如何操作。大多数情况下,这是一种改进(例如在安全性方面),因此如果您关心代码,您确实应该处理这些警告。

Edit:I think it's noteworthy in this context to look for strict standards noticesPHP Manualas well. They are somewhat related because these notices are useful hints for changes in the language as well.

编辑:我认为在这种情况下,寻找严格的标准通知PHP 手册也是值得注意的。它们有些相关,因为这些通知也是语言变化的有用提示。

Enabling E_STRICTduring development has some benefits. STRICT messages will help you to use the latest and greatest suggested method of coding, for example warn you about using deprecated functions.

在开发期间启用E_STRICT有一些好处。STRICT 消息将帮助您使用最新和最好的建议编码方法,例如警告您使用已弃用的函数。

(from the PHP Manual link above)

(来自上面的 PHP 手册链接)

回答by zzzzBov

I believe PHP continues to execute the function while additionally triggering an error stating that the function is deprecated.

我相信 PHP 会继续执行该函数,同时还会触发一个错误,指出该函数已被弃用。

Ye Olde Version:

叶老版:

function foo(){
  bar();
}

New Version:

新版本:

function foo(){
  bar();
  trigger_error('Deprecated: this function is deprecated foo!', E_NOTICE);
}

Note: this is probably notwhat's actuallyhappening behind-the-scenes, but it would be relatively equivalent.

注意:这可能不是什么实际发生的幕后的,但它是相对等同。

回答by Ignacio Vazquez-Abrams

They will proceed to run as documented, but they may be removed in the future and so should be converted as soon as possible in existing code, and not used in new code.

它们将按照文档继续运行,但将来可能会被删除,因此应尽快在现有代码中进行转换,而不是在新代码中使用。

回答by Paul

Deprecated features work, but there are better alternatives, and they may be removed in future versions of PHP.

不推荐使用的功能可以工作,但有更好的替代方案,它们可能会在 PHP 的未来版本中删除。

回答by PeeHaa

They still get executed as 'normally'.

他们仍然像“正常”一样被执行。

However you need to ditch them as fast as you can for you code to keep on working in the future.

但是,您需要尽快抛弃它们,以便您的代码在未来继续工作。

回答by phihag

Aside from emitting deprecation warnings, the code will work fine. The deprecation indicates the feature in question may be removed in the future.

除了发出弃用警告外,代码还可以正常工作。弃用表示将来可能会删除有问题的功能。

This warningrefers to a line like

此警告指的是像这样的行

$obj =& new MyClass();

The ampersand is not required any more since php 5; you can simply write

自 php 5 起不再需要 & 符号;你可以简单地写

$obj = new MyClass();

回答by Marc B

Nothing, it's just a warning. Read it as "this function still works as documented for this version of PHP, but all bets are off in future versions". Internally there's no difference at all, except for adding the deprecation warnings.

没什么,这只是一个警告。将其读作“此功能仍然按照此版本 PHP 的文档工作,但在未来版本中所有赌注都将关闭”。在内部没有任何区别,除了添加弃用警告。

回答by Nasir Iqbal

The depreciated functions still exist however you get the warning, meaning that such functions will not be available in future.

折旧的功能仍然存在,但您会收到警告,这意味着此类功能将来将不可用。