其他变更
性能提升
PHP 核心
为 array_key_exists() 函数添加了一个专门的 VM opcache
优化,如果该函数可以被静态解析,则可以提高该函数的性能。如果你在项目中使用了命名空间,可能会需要使用
\array_key_exists()
来显性的导入该函数。
正则表达式 (Perl-Compatible)
当对同一字符串(但可能有不同的偏移量)在 UTF-8 模式("u"
修饰符)下重复调用 preg_match() 时,只会检查一次 UTF-8 有效性。
INI 配置文件处理的变化
zend.exception_ignore_args 是新的 INI 指令,用于包含或排除异常生成的栈跟踪中的参数。
opcache.preload_user 是新的 INI 指令,用于指定当以 root(出于安全原因不允许这样做)执行时,执行预加载代码的用户帐户。
迁移到 pkg-config
一些扩展已经迁移到只使用 pkg-config 来检测库的依赖性。一般来说,这意味着不再用
--with-foo-dir=DIR 或类似的参数,而是使用
--with-foo。自定义库的路径可以通过向 PKG_CONFIG_PATH
添加额外的目录,或通过 FOO_CFLAGS
和 FOO_LIBS
来明确指定。
以下扩展和 SAPI 会受到影响:
-
CURL:
- --with-curl 选项不再接受一个目录。
-
Enchant:
- --with-enchant 选项不再接受一个目录。
-
FPM:
- --with-fpm-systemd 现在仅使用 pkg-config 进行 libsystem 检查。libsystemd 所需的最低版本是 209。
-
GD:
- --with-gd 改变为 --enable-gd(是否启用扩展)和 --with-external-gd(选择使用外部 libgd,而不是捆绑 libgd)。
- --with-png-dir 参数被移除。需要 libpng 支持。
- --with-zlib-dir 参数被移除。需要 zlib 支持。
- --with-freetype-dir 改变为 --with-freetype
- --with-jpeg-dir 改变为 --with-jpeg
- --with-webp-dir 改变为 --with-webp
- --with-xpm-dir 改变为 --with-xpm
-
IMAP:
- --with-kerberos-systemd 选项不再接受一个目录。
-
Intl:
- --with-icu-dir 被移除。如果使用了 --enable-intl 参数,需要 libicu 支持。
-
LDAP:
- --with-ldap-sasl 选项不再接受一个目录。
-
Libxml:
- --with-libxml-dir 被移除。
- --enable-libxml 改变为 --with-libxml。
- --with-libexpat-dir 被重命名为 --with-expat 并且该选项不再接受一个目录。
-
Litespeed:
- --with-litespeed 改变为 --enable-litespeed。
-
Mbstring:
- --with-onig 被移除。如果指定了 --disable-mbregex 参数,则需要 libonig 支持。
-
ODBC:
- --with-iodbc 选项不再接受一个目录。
- --with-unixODBC 现在没有目录时使用 pkg-config(首选)。对于没有 libodbc.pc 的旧版本,仍然接受目录。
-
OpenSSL:
- --with-openssl 选项不再接受一个目录。
-
PCRE:
- --with-pcre-regex 已移除。而是提供了 --with-external-pcre 来选择使用外部 PCRE 库,而不是捆绑的那个。
-
PDO_SQLite:
- --with-pdo-sqlite 选项不再接受一个目录。
-
Readline:
- --with-libedit 选项不再接受一个目录。
-
Sodium:
- --with-sodium 选项不再接受一个目录。
-
SQLite3:
- --with-sqlite3 选项不再接受一个目录。
-
XSL:
- --with-xsl 选项不再接受一个目录。
-
Zip:
- --with-libzip 已移除。
- --enable-zip 改变为 --with-zip。
CSV 转义
现在 fputcsv()、fgetcsv()、SplFileObject::fputcsv()、SplFileObject::fgetcsv()
和 SplFileObject::setCsvControl() 的 $escape
参数 接受空字符,这会禁用 PHP 专有的转义机制。
str_getcsv() 的行为已相应调整(之前空字符串与使用默认值相同)。
SplFileObject::getCsvControl() 也可以相应的为第三个数组元素返回空字符串。
数据过滤
filter 扩展不再展示用于 Unix 构建的 --with-pcre-dir,并且现在可以在使用 ./configure 时可靠地编译为共享。
GD
捆绑 libgd 中 imagecropauto() 的行为已与系统 libgd 的行为同步:
-
IMG_CROP_DEFAULT
不再回退到IMG_CROP_SIDES
- 阈值裁剪(threshold-cropping)现在使用系统 libgd 算法
imagecropauto() 的默认 $mode
参数已更改为
IMG_CROP_DEFAULT
;现已弃用传递 -1
。
imagescale() 现在支持将 -1
传递给
$new_width
,从而保留宽高比以缩放到固定的高度。
轻量级目录访问协议
移除对 nsldap 和 umich_ldap 的支持。
Libxml
所有基于 libxml 的扩展现在都需要 libxml 2.7.6 及其更高的版本。
多字节字符串
oniguruma 库不再与 PHP 捆绑,而是需要在系统上提供 libonig。或者可以使用 --disable-mbregex 禁用 mbregex 组件。
OPcache
--disable-opcache-file 和 --enable-opcache-file 配置选项已移除,以支持 opcache.file_cache INI 指令。
密码散列
现在 password_hash() 和 password_needs_rehash()
函数接受可以为 null 的字符串和 int 作为 $algo
参数。
PEAR
默认不再启用 PEAR(包括 PECL)的安装。可以使用 --with-pear 手动启用它。此选项已弃用,将来可能会移除。
Reflection
ReflectionClass、ReflectionFunction、ReflectionMethod、ReflectionObject
和 ReflectionProperty 类的修饰符常量
(IS_ABSTRACT
、IS_DEPRECATED
、IS_EXPLICIT_ABSTRACT
、IS_FINAL
、IS_IMPLICIT_ABSTRACT
、IS_PRIVATE
、IS_PROTECTED
、IS_PUBLIC
和 IS_STATIC
) 的数值已经更改。
SimpleXML
SimpleXMLElement 现在实现了 Countable。
SQLite3
捆绑的 libsqlite 已移除。要编译 SQLite3 扩展,现在需要系统 libsqlite3 ≥ 3.7.4。要编译 PDO_SQLite 扩展,现在需要系统 libsqlite3 ≥ 3.5.0。
现在明确禁止 SQLite3、SQLite3Stmt 和 SQLite3Result 的序列化和反序列化。以前,可以序列化这些类的实例,但反序列化会产生不能用的对象。
@param
表示法现在也可用于表示 SQL 查询参数。
Zip
捆绑的 libzip 库已移除。编译 zip 扩展现在需要系统 libzip >= 0.11。
用户贡献的备注 3 notes
This version brings an important changes with the directive zend.exception_ignore_args set to On by default.
In all stack traces, the args key is now missing.
All php frameworks have to handle this to report errors & exceptions.
As of PHP 7.4, an exception thrown within the user-defined shutdown function can be caught by the user-defined exception handler.
<?php
set_error_handler(
function($level, $error, $file, $line){
if(0 === error_reporting()){
return false;
}
throw new ErrorException($error, -1, $level, $file, $line);
},
E_ALL
);
register_shutdown_function(function(){
$error = error_get_last();
if($error){
throw new ErrorException($error['message'], -1, $error['type'], $error['file'], $error['line']);
}
});
set_exception_handler(function($exception){
// ... more code ...
});
require 'NotExists.php';
Note for internals/extensions:
Many opcode values changed between PHP 7.3 and 7.4, so most documentation resources are outdated in that regard. You can look the definitions at Zend/zend_vm_opcodes.h in php-src. For example, ZEND_ECHO changes from 40 to 136.
While opcode changes happen in a lot of PHP versions, the change in 7.4 is quite significant.
备份地址:http://www.lvesu.com/blog/php/migration74.other-changes.php