您将 PHP 4 迁移到 PHP 5 的经验
我们必须将大约 50 多个应用程序(小型/大型)迁移到 PHP 5.3(从 PHP 4.1).是否有人对此类任务有任何经验?
We have to move around 50+ Applications (small / large) to PHP 5.3 (from PHP 4.1). Does some has any experience with such an task?
- 所需时间
- 工具
- 环境的最佳设置(服务器/测试?)
首先迁移到 PHP 5.2 有意义吗?有什么方法可以自动检测使用PHP 4 功能"的应用程序,而这在 PHP 5 中不起作用?
Does it make sense to move first to PHP 5.2? Is there any way to automatic detect applications using "PHP 4 Features" wich wont work in PHP 5?
我不知道如何处理这样的项目.谢谢!
I have no idea how to handle such an project. Thanks!
推荐答案
在 PHP4 和 PHP5 之间,类的一些语法发生了变化——例如,在 PHP4 中,构造函数方法的名称与类相同,而在 PHP5 中,构造函数的名称为
__construct()
.
PHP5 仍然可以处理 PHP4 样式的类定义,因此您的代码可能仍然可以工作,但是仍然建议您将它们更改为新样式,因为那里有很多功能,否则您将无法使用.此外,当然,旧的语法最终会被删除;您的 PHP4 类将来会中断,所以最好现在就更改它们,而不是等到紧急情况发生.
Some of the syntax for classes has changed between PHP4 and PHP5 - for example, in PHP4, the constructor method was named the same as the class, whereas in PHP5, the constructor is named
__construct()
.
PHP5 can still cope with PHP4-style class definitions, so your code is likely to still work, but you would nevertheless be well advised to change them to the new style, as there are a lot of features that you won't be able to use otherwise. In addition, of course, the old syntax will be removed eventually; your PHP4 classes will break in the future, so better to change them now rather than waiting till it's urgent.
全局变量.您应该已经在 PHP4 中大量使用过 $_REQUEST
、$_POST
、$_GET
和 $_COOKIES
旧代码可能仍在使用 PHP3 标准的旧样式自动全局变量.这是一个巨大的安全风险,所以如果你还在使用 register_globals
,你现在应该开始处理你的代码,至少在你去过的每个地方都使用 $_REQUEST
使用了自动全局.这实际上可能是一项非常艰巨的任务——当代码中没有任何内容表明一种或另一种方式时,很难在一个大型应用程序中试图找出哪些变量是全局变量,哪些不是全局变量.从不得不这样做的人那里拿走它,这可能是一场真正的噩梦.但这并不是迁移到 PHP5 所特有的——正如我所说,即使您坚持使用 PHP4,您也确实需要处理这个问题.PHP5 没有改变任何东西,除了 register_globals
标志现在默认关闭,这可能会给你更多的动力去实际做这项工作.
Globals. You should already have been using $_REQUEST
, $_POST
, $_GET
and $_COOKIES
in PHP4, a lot of older code may still be using the old style auto-globals that was standard ing PHP3. This is a massive security risk, so if you are still using register_globals
, you should start working on your code now to at least use $_REQUEST
instead for every place you've used an auto-global. This can actully be a very difficult task -- it can be hard to trawl through a large application trying to work out which variables are intended to be globals and which aren't, when there's nothing in the code to indicate one way or the other. Take it from someone who's had to do this, it can be a real nightmare. But this isn't something specific to moving to PHP5 -- as I said, even if you stick to PHP4, you really do need to deal with this issue. PHP5 doesn't change anything, except that the register_globals
flag is now defaulted to being switched off, which may give you a bit more impetus to actually do this work.
如果您使用任何 ereg_
正则表达式函数,这些函数已被弃用.您应该将它们替换为等效的 preg_
函数.这不是一项大任务,实际上这些功能仍然可用,所以它可以等待,只要您准备好忽略告诉您该功能已弃用的警告.但同样,与类语法一样,现在考虑更改它们可能是明智的.
If you use any ereg_
regex functions, these have been deprecated. You should replace them with the equivalent preg_
functions. This isn't a big task, and in fact the functions are still available, so it can wait, as long as you're prepared to ignore the warnings telling you the function is deprecated. But again, as with the class syntax, it may be sensible to consider changing them now.
另一个改变的特性是引用传递,旧语法已被弃用.在 PHP4 中,我们鼓励在函数调用中使用 &
字符通过引用传递变量.在 PHP5 中,正确的做法是将 &
字符放在函数声明中,而不是在你调用它的地方.同样,旧语法仍然有效,但前提是您可以忍受 PHP 到处向您抛出警告.
Another feature that has changed, where the old syntax has been deprecated is passing-by-reference. In PHP4, we were encouraged to use the &
character in the function call to pass variables by reference. In PHP5, the correct way of doing it is to put the &
character in the function declaration rather than where you call it. Again, the old syntax still works, but only if you can put up with PHP throwing warnings at you all over the place.
相关文章