Home php教程 php手册 PHP5.2 到5.3的升级 (1)

PHP5.2 到5.3的升级 (1)

Jun 06, 2016 pm 08:00 PM
php upgrade

PHP5.3出来好久了, 之前一直没有时间来看这两者之间的差别。 现在5.2已经不再被sustain了, 后面应该考虑向5.3进行migration了。 所以来研究一下。 1. PHP5.3有什么改变 5.3还是保留了大部分向前兼容的。 但是还是有部分是不兼容的。 首先来看看不兼容

PHP5.3出来好久了, 之前一直没有时间来看这两者之间的差别。

 

现在5.2已经不再被sustain了, 后面应该考虑向5.3进行migration了。

 

所以来研究一下。

 

1. PHP5.3有什么改变

5.3还是保留了大部分向前兼容的。 但是还是有部分是不兼容的。

首先来看看不兼容的改变有哪些?

语法变化

  该语言新增了名称空间(namespace)和闭包(closure)增加了更多的保留字。从 PHP V5.3 开始,namespace 不再用作标识符。closure 类现在是一个保留类,但它仍然可以作为有效的标识符。

      PHP V5.3 中还增加了对 goto 语句的支持。现在,goto 是一个保留字。goto 语句在现代语言中不太常见(您也许记得在 BASIC 中如何使用 goto),但是有些情况下,goto 语句的确方便。

 

函数和方法的变化

  在 PHP V5.3 中,函数和方法没有大的变化,但还是有一些增强,以帮助解决 PHP 中的一些突出问题并提高性能。本节讨论一些较为显著的变化。

  在之前版本的 PHP 中,数组函数 atsort、natcasesort、usort、uasort、uksort、array_flip 和 array_unique 可以以参数形式传递对象而不是数组。然后,这些函数将对象的属性当做数组的键和值。PHP V5.3 中不再支持这一点,所以需要首先将对象转换成数组。

      在 Windows 上,有些函数之前在 PHP 中不受支持,现在在 PHP V5.3 中获得支持。例如,getopt() 函数用于解析从命令行调用 PHP 脚本时使用的选项。用于编码和解码 Internet 地址的 inet_ntop() 和 inet_pton() 函数,现在也可以在 Windows® 上使用。还有一些数学函数,例如 asinh()、acosh()、atanh()、log1p() 和 expm1(),现在在 Windows 上也受支持。

 

扩展的变化

 

PHP Extension C Library(PECL)一直都是 PHP 中的新扩展的来源地。当一个扩展已经成熟和稳定,并且被认为可以成为核心发行版中一个有用的功能,那么它通常在重大的版本变更时被添加进来。根据这条规则,从 PHP V5.3 开始,下面的扩展会成为核心 PHP 发行版中的一部分。

  FileInfo提供帮助检测文件的内容类型和编码的函数,这些函数通过查看文件中的某些魔术字节字符序列进行检测。intlInternational Components for Unicode(ICU)库的一个包装器,提供用于 unicode 和全球化支持的函数。Phar第 4 部分 中讨论过的一个 PHP 归档工具。mysqlnd用于 MySQL 数据库访问的一个本地 PHP 驱动程序,是早期利用 libmysql 库的 MySQL 和 MySQLi 扩展的替代物。SQLite3用于使用 SQLite V3 数据库的一个库。

  当一个扩展不再受到积极的维护,或者被认为不值得随核心 PHP 发行版一起发行时,它通常被转移到 PECL。在 PHP V5.3 的改造过程中,下面这些扩展被踢出核心 PHP 发行版,而放在 PECL 中进行维护。

  ncurses对 curses 的模拟,用于在命令行显示图形化的输出。fpdf用于在 PDF 文档中构建和使用表单和表单数据。dbase提供读写 dbase 兼容文件的支持。fbsql支持 Frontbase 数据库服务器上的数据库访问。ming一个开源库,用于创建 Flash 4 动画。

  Sybase 扩展已经被完全移除,取而代之的是 sybase_ct 扩展。sybase_ct 扩展与前者完全兼容,应该是一个简易替代者(drop-in replacement)。这个更新的功能将使用 Sybase client 库,需要将这些库安装在 Web 服务器上。

 

构建的变化

PHP V5.3 着重改善了构建过程,因此更容易在所有平台上构建 PHP。为了维护 PHP 构建之间的一致性,并提供一组可靠的组件,在构建中不再禁用 PCRE、Reflection 和 SPL 扩展。现在,可以构建可分发的 PHP 应用程序,它们将使用这些扩展并且保证这些扩展是可用的。

  一个新的团队在去年接管了 PHP Windows 构建。这个小组将为 Windows 上的用户提供一些改进。新的构建将以 586 架构(Intel® Pentium® 或更高型号)为目标,并要求 Windows 2000/XP 或更高版本,另外去掉了对 Windows 98/NT 及之前版本的支持。将构建使用 Microsoft® Visual Studio® 2008 构建的 PHP 构建和针对 x86-64 架构的构建。当和 Microsoft IIS Web 服务器上的 FastCGI 或者和 Apache 一起使用时,在使用相同的编译器和架构进行构建的情况下,它们可以提供更高的性能。Windows 安装程序也将有所改进,以便更好地在 Microsoft IIS Web 服务器上配置 PHP。

 

.ini 的变化

  PHP 的一个重要特性是,可以使用 .ini 文件配置它的行为。在 PHP V5.3 中,与这个文件有关的一些有问题的指令已经被删除,例如 zend.ze1_compatibility_mode。现在,在使用这个文件时,灵活性有了巨大的提高。

  对于 php.ini 文件有两个重大的改进:

  在 php.ini 文件中可以使用变量。这对于减少该文件的冗余非常方便,必要时更新文件也更加方便。

      和用 Apache 配置文件进行设置一样,可以进行 per-directory 和 per-site PHP ini 设置。这样做的优点是,在所有不同的可运行 PHP 的 SAPI 中,语法都是一致的。

 

放弃的特性

  PHP V5.3 开始正式放弃一些较旧的函数,将来版本的 PHP 中将不再提供它们。当使用这些函数时,会遇到 E_DEPRECATED 错误。以下函数在 PHP V5.3 中被遗弃:

  tick(declare(ticks=N) 和 register_tick_function()),之前用于在 declare() 块中当解析器每执行 n 条语句时就进行一个函数调用。它们将被废除,因为它们的函数中有很多的中断,而且该特性不大常用。

  define_syslog_variables(),该函数初始化所有与 syslog 相关的变量。该函数不是必需的,因为它定义的常量已经被全局定义。废除这个函数调用应该是有必要的。

  ereg 正则表达式函数。建议使用 PCRE 正则表达式函数替代,因为它们更快,并且与其他语言和应用程序中使用的正则表达式更加一致。对 ereg 函数的支持将被废除,以使 PHP 可以标准化地使用一个正则表达式引擎。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

See all articles