Skip to content

PHP 8.3 官方 Release Notes 深度拆解大典

参考官方文档: PHP 8.3 Official Release Notes
PHP 8.x 是 PHP 语言史上最伟大的演进时代。它通过 JIT 编译器Typed Class Constants (类型化常量)readonly 只读类与属性enum 枚举match 表达式 彻底把 PHP 转化为了兼具极速与强类型的现代语言。


🐳 容器运行环境 (Runtime Environment)

在标准 Docker 镜像 php:8.3-alpine 中执行控制台诊断指令 php -v

📸 Unverified Snapshot📋php:8.3-alpine
⏱️ 671msNot verified
PHP 8.3.33 (cli) (built: Jul 30 2026 22:53:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.33, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.33, Copyright (c), by Zend Technologies

1. 🔀 match 表达式与 enum 枚举

代替传统的 switch,提供严格类型比对 (===) 的 match 表达式;引入具备类型与方法的优雅 enum 枚举。

php
// 关联源码: demos/php/php8_demo.php
enum ServerStatus: string {
    case Active = 'active';
    case Maintenance = 'maintenance';
}

$message = match ($status) {
    ServerStatus::Active => 'Server is running normally',
    ServerStatus::Maintenance => 'Server is under maintenance',
};

2. 🛡️ readonly 只读属性与只读类 (PHP 8.1 / 8.2)

允许将类声明为 readonly,声明后类内部所有属性均不可二次修改,极大提升不可变数据结构的安全性。

php
readonly class UserProfile {
    public function __construct(
        public int $id,
        public string $username,
        public ServerStatus $status
    ) {}
}
📸 Unverified Snapshot📋php:8.3-alpine
⏱️ 639msNot verified
PHP Version: 8.3.33
User: Alice (ID: 101)
Status: active -> Server is running normally

Released under the MIT License.