您的经验将PHP 4迁移到PHP 5 [英] Your experience Moving PHP 4 to PHP 5

查看:58
本文介绍了您的经验将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 5中无法使用"PHP 4功能"自动检测应用程序吗?

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!

推荐答案

  1. 在PHP4和PHP5之间,类的某些语法已更改-例如,在PHP4中,构造函数方法的名称与类相同,而在PHP5中,构造函数命名为__construct(). />
    PHP5仍然可以处理PHP4样式的类定义,因此您的代码可能仍然可以工作,但是仍然建议您将其更改为新样式,因为您有很多功能否则将无法使用.另外,当然,旧的语法最终将被删除.您的PHP4类将来会中断,因此最好立即更改它们,而不要等到紧迫为止.

  1. 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_ regex函数,则这些函数已被弃用.您应该将它们替换为等效的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.

这篇关于您的经验将PHP 4迁移到PHP 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆