迁移到较新版本的 PHP

2022-01-23 00:00:00 migration php

我注意到几周前 PHP 5.3 达到了候选发布阶段(哇!),但随后看到已经弃用的函数列表最终被删除,这让我开始思考它是否会破坏我的任何旧代码.

I notice that a couple of weeks ago PHP 5.3 reached release candidate stage (woo!), but then seeing the list of already-deprecated functions finally being removed, that got me thinking about whether it would break any of my old code.

没有进行一目了然"的测试(在测试服务器上安装并试用),是否有任何类型的迁移工具可以分析您的代码以突出显示问题?例如,如果某些脚本使用 ereg_* 函数.

Short of doing a suck-it-and-see test (installing on a test server and trying it out), are there any sort of migration tools which can analyse your code to highlight issues? For example, if some scripts use the ereg_* functions.

推荐答案

您可以使用的一种技术是获取正在被删除的已弃用函数的列表并为它们 grep.对于这样的事情,一点 shell 脚本 fu 大有帮助.

One technique you could use is to take the list of deprecated functions that is being removed and grep for them. A little shell scripting fu goes a long way for things like this.

假设您有一个 deprecated.txt 文件,其中每行一个不推荐使用的函数名称:

Let's suppose you have a file deprecated.txt with deprecated function names one per line:

for func in `cat deprecated.txt`
do
  grep -R $func /path/to/src
done

这将告诉您正在使用的已弃用函数的所有实例.

That will tell you all the instances of the deprecated functions you're using.

相关文章