PHP 8.3.4 Released!

其他变更

性能提升

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_CFLAGSFOO_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,从而保留宽高比以缩放到固定的高度。

HASH 消息摘要框架

不能再禁用 hash 扩展,并且始终是编译 PHP 的组成部分,类似于 date 扩展。

Intl

intl 扩展现在至少需要 ICU 50.1。

ResourceBundle 现在实现了 Countable

轻量级目录访问协议

移除对 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

ReflectionClassReflectionFunctionReflectionMethodReflectionObjectReflectionProperty 类的修饰符常量 (IS_ABSTRACTIS_DEPRECATEDIS_EXPLICIT_ABSTRACTIS_FINALIS_IMPLICIT_ABSTRACTIS_PRIVATEIS_PROTECTEDIS_PUBLICIS_STATIC) 的数值已经更改。

SimpleXML

SimpleXMLElement 现在实现了 Countable

SQLite3

捆绑的 libsqlite 已移除。要编译 SQLite3 扩展,现在需要系统 libsqlite3 ≥ 3.7.4。要编译 PDO_SQLite 扩展,现在需要系统 libsqlite3 ≥ 3.5.0。

现在明确禁止 SQLite3SQLite3StmtSQLite3Result 的序列化和反序列化。以前,可以序列化这些类的实例,但反序列化会产生不能用的对象。

@param 表示法现在也可用于表示 SQL 查询参数。

Zip

捆绑的 libzip 库已移除。编译 zip 扩展现在需要系统 libzip >= 0.11。

add a note

User Contributed Notes 3 notes

up
2
Florent H (Sowapps)
4 years ago
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.
up
1
ohcc at 163 dot com
3 years ago
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';
up
0
santi at mola dot io
3 years ago
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.
To Top