从 PHP 4 移植到 PHP 5

本章节将帮你从 PHP 4 移植到 PHP 5。

从 PHP 4 向 PHP 5 移植

尽管 PHP 5 提供了很多新特性,但它还是尽可能设计得与之前版本的 PHP 兼容,只有很少功能不一致。

确认阅读了本手册中相应的 PHP 5 移植附录,它包含了更多移植到 PHP 5 的信息。

PHP 5 中还能用 MySQL 吗?好像找不到了。

MySQL依然被支持,唯一区别是 PHP 5 中 默认为不激活。这意味着在 PHP 的 configure一行中不包含有 --with-mysql选项,因此必须在编译时手工加入。Windows 用户可以编辑 php.ini 并激活 php_mysql.dllDLL。在 PHP 4 中没有这个 DLL,因为已经编译进 PHP 可执行文件中去了。

此外,MySQL 客户端库也不再绑定于 PHP 中了。有关此题目的更多细节见 此 FAQ。另外确保阅读了 MySQL 章节中的安装详情。一个配置行的例子是 --with-mysql=/usr,Windows 用户则需要 libmySQL.dll

听说 PHP 有个全新的 OOP 模型,那现有的 OOP 代码还能运行吗?上哪去找这些新的 OOP 特性的信息?

PHP 5 的主要改进就是 OOP 模型现在使用了 Zend Engine 2.0zend.ze1_compatibility_mode指令将激活与 Zend Engine 1.0(PHP 4)的兼容性。

新的 OOP 模型文档见 OOP 语言手册OOP 移植附录章节。

除了 OOP 模型,PHP 5 还有哪些改动?此外,有没有专门针对 PHP 5 的手册?

其它几个改动见 移植到 PHP 5 附录。没有专门的 PHP 5 手册,因为 PHP 的主要部分还是一样的。

add a note

User Contributed Notes 2 notes

up
-4
gfrank at neoservers dot com
8 years ago
To get PHP5 and PHP4 to work at the same time you will also need to change all "php_value", "php_flag", "php_admin_flag", and "php_admin_value" occurences; otherwise, you can't set configuration file settings.
up
-7
odnowa-sql at o2 dot no-spam pl
9 years ago
You can run PHP4 and PHP5 as Apache2 modules at the same time. The trick is to hack the sources a little bit.
Change all occurences of application/x-httpd-php (and MIME type for sources) to application/x-httpd-php5 and then add that mime type to apache conf.