已弃用的函数:require_once()

发布于 2024-10-14 02:19:44 字数 627 浏览 2 评论 0原文

最近,我开始将 PHP 5.2.x 上的 Drupal 6 模块转换为 PHP 5.3.x 上的 Drupal 7,现在我收到以下警告

已弃用的函数:分配 通过引用 new 的返回值为 在 require_once() 中已弃用(行 27 的 C:\Users\ajinkya\Desktop\xampp\php\PEAR\SOAP\WSDL.php)。

WSDL.php 的第 27 行是: require_once 'HTTP/Request.php';

我无法弄清楚此警告的原因是什么。 PHP 5.3.x 中 require_once() 的行为是否发生了变化?

Drupal 7 中的 file.inc 有一行: require_once DRUPAL_ROOT 。 '/includes/stream_wrappers.inc; 并且它不会抛出任何警告。为什么?

如果我将error_reporting(E_ALL & ~E_DEPRECATED);放入Drupal 7的setting.php中,警告就会消失。压制这样的警告好吗?

Recently, I started converting my Drupal 6 module on PHP 5.2.x to Drupal 7 on PHP 5.3.x, and now I get following warning

Deprecated function: Assigning the
return value of new by reference is
deprecated in require_once() (line
27 of
C:\Users\ajinkya\Desktop\xampp\php\PEAR\SOAP\WSDL.php).

Line 27 of WSDL.php is : require_once 'HTTP/Request.php';

I am not able to figure out what is the cause of this warning. Has the behavior of require_once() changed in PHP 5.3.x?

file.inc in Drupal 7 has a line : require_once DRUPAL_ROOT . '/includes/stream_wrappers.inc; and it does not throw any warning. Why?

If I put error_reporting(E_ALL & ~E_DEPRECATED); in a setting.php of Drupal 7, the warning goes away. Is it good to suppress a warning like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

(り薆情海 2024-10-21 02:19:44

抑制这样的错误有好处吗?

视情况而定。忽略错误从来都不是一个好主意。对于开发阶段来说,保持严格的报告启用是一个好主意。然而,一旦 PHP 向您提供类似的调试消息,您就可以对其进行评估并据此做出明智的决定。

您可以解决上述问题、修复它,或者如果不是实际问题则忽略它。

通过引用分配对象是不需要的,因此不推荐使用。然而,这并不是一个会导致错误的问题,而且它永远不会在语义上被禁止。在未来版本中删除语法构造会破坏兼容性,因此不会发生。在这种情况下,明智的选择是要么确认并忽略语法提示,要么删除 &,因为它是不需要的,并且在这种特定情况下删除它不太可能破坏行为。

It is good to suppress an error like that?

Depends. Ignoring errors is never a good idea. Keeping strict reporting enabled is a good idea for the development stage. However, once PHP advises you with a debug message like that, you evaluate it and base an informed decision on that.

You can either work around the mentioned issue, fix it, or ignore it if it's not an actual problem.

Assigning an object by reference is unneeded and henceforth deprecated. It's however not a problem that will lead to errors, and it will never be semantically forbidden. Removing the syntax construct in future versions would break compatibility, so won't happen. The informed choice in this case is either to acknowledge and ignore the syntax hint, or remove the & since it's unneeded and its removal in this particular instance is mostly unlikely to break the behaviour.

↘紸啶 2024-10-21 02:19:44

错误消息表明代码正在使用 $something = &new SomeObject(); 而不是 $something = new SomeObject();

&new 在古代 PHP 版本中是必要的,以确保对象始终通过引用传递。但在最近的版本中,根本没有理由这样做,因此它已被弃用。

我不知道为什么你的 PHP 报告不正确的文件名/行号...

The error message says that the code is using $something = &new SomeObject(); instead of $something = new SomeObject();.

&new was necessary in ancient PHP versions to ensure objects were always passed by reference. But in recent versions there is no reason to do this at all so it's deprecated.

I have no idea why your PHP reports an incorrect filename/line number though...

从﹋此江山别 2024-10-21 02:19:44

我在 PHP 网站上没有看到任何内容表明 require_once 已弃用。也许 HTTP/Request.php 中的某些内容已被弃用?这是一个非常奇怪的警告。

I don't see anything on the PHP site indicating that require_once is deprecated. Perhaps something inside of HTTP/Request.php is deprecated instead? This is a pretty odd warning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文