更新到 PHP 5.3,禁用不推荐使用的函数警告

发布于 2024-09-30 22:41:24 字数 258 浏览 0 评论 0原文

我非常渴望将我们的一些服务器更新到 PHP 5.3。这将为 Zend Framework 2 以及明显的性能更新做好准备。不幸的是,我在这些服务器上有大量遗留代码,这些代码会及时修复,但在迁移之前无法全部修复。我正在考虑更新但禁用除少数开发站点之外的所有开发站点上的已弃用功能错误,在这些站点上我可以开始更新旧代码。

error_reporting(E_ALL ^ E_DEPRECATED);

有什么根本原因说明这不是一个好主意吗?

I'm very keen to update a number of our servers to PHP 5.3. This would be in readiness for Zend Framework 2 and also for the apparent performance updates. Unfortunately, i have large amounts of legacy code on these servers which in time will be fixed, but cannot all be fixed before the migration. I'm considering updating but disabling the deprecated function error on all but a few development sites where i can begin to work through updating old code.

error_reporting(E_ALL ^ E_DEPRECATED);

Is there any fundamental reason why this would be a bad idea?

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

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

发布评论

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

评论(3

网白 2024-10-07 22:41:24

好吧,您可能会忘记您设置了该标志,并想知道为什么您的应用程序会在下一次 PHP 更新中中断。如果没有正确的错误报告,调试应用程序可能会非常令人沮丧。这是我能想到的原因之一。

但是,如果您这样做了,请在某处记录下来。它可以为您节省几个小时,然后您才记得设置标志。

Well, you could forget that you set the flag and wonder why your application breaks in a next PHP update. It can be very frustrating to debug an application without proper error reporting. That's one reason I can think of.

However, if you do it, document it somewhere. It can save you a couple of hours before you remember setting the flag at all.

挽手叙旧 2024-10-07 22:41:24

如果您还没有阅读迁移指南,请特别关注向后不兼容更改已删除扩展

你有比弃用更大的问题。忽略 E_DEPRECATED 是不够的。由于不兼容的更改,还会出现其他类型的错误,或者更糟糕的是,出现意外行为。

这是一个简单的示例:

<?php
function goto($line){
    echo $line;
}
goto(7);
?>

此代码在 PHP 5.2.x 中可以正常工作并输出 7,但在 PHP 5.3.x 中会出现解析错误。

您需要做的是获取该指南中的每一项并检查您的代码并在需要时进行更新。为了加快速度,您可以在第一阶段忽略已弃用的功能,并仅禁用 E_DEPRECATED 的错误报告,但您不能假设您只会收到一些无害的警告当移植到另一个主要的 PHP 分支时。

另外,不要忘记您的黑客行为并尽快修复已弃用的问题。

问候,
Alin

注意:我试图从实际角度回答这个问题,所以请不要告诉我忽略警告是不好的。我知道这一点,但我也知道时间不是无限的资源。

If you haven't already you should read the migration guide with particular focus on Backward Incompatible Changes and Removed Extensions.

You have bigger issues than deprecation. Ignoring E_DEPRECATED will not suffice. Because of the incompatible changes there will also be other type of errors or, maybe, even worse, unexpected behaviors.

Here's a simple example:

<?php
function goto($line){
    echo $line;
}
goto(7);
?>

This code will work fine and output 7 in PHP 5.2.x but will give you a parse error in PHP 5.3.x.

What you need to do is take each item in that guide and check your code and update where needed. To make this faster you could ignore the deprecated functionality in a first phase and just disable error reporting for E_DEPRECATED, but you can't assume that you will only get some harmless warnings when porting to another major PHP branch.

Also don't forget about your hack and fix the deprecated issues as soon as possible.

Regards,
Alin

Note: I tried to answer the question from a practical point of view, so please don't tell me that ignoring warnings is bad. I know that, but I also know that time is not an infinite resource.

离去的眼神 2024-10-07 22:41:24

我想你有某种测试服务器?如果没有,您确实应该设置一个并在 PHP 5.3 中测试您的代码。如果您的代码经过彻底的单元测试,测试将需要几秒钟的时间,并且修复它也会相当快,因为​​单元测试会告诉您确切的位置。如果没有,那么考虑在下一个版本之前将单元测试作为优先事项,同时检查所有内容,首先禁用 E_DEPRECATED 警告并修复出现的任何问题,然后重新进行一旦你有时间就启用。您还可以运行全局查找和替换以更轻松地修复错误。

I presume you have some kind of test server? If not, you really should set one up and test your code in PHP 5.3. If your code is thoroughly Unit Tested, testing it will take seconds, and fixing it will be fairly quick too, as the unit tests will tell you exactly where to look. If not, then consider making Unit Testing it all a priority before the next release, and in the meantime go through it all, first with E_DEPRECATED warnings disabled and fix anything which comes up, then with it re-enabled once you have time. You could also run a global find-and-replace for easier to fix errors.

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