PHP 8.5.0 Beta 1 available for testing

单例类型

单例类型(singleton type)是只允许单个值的类型。PHP 支持两种单例类型:false(自 PHP 8.0.0 起支持),true(自 PHP 8.2.0 起支持)。

警告

在 PHP 8.2.0 之前,false 类型只能用作联合类型的一部分。

注意: 无法定义自定义单例类型。建议改用枚举

添加备注

用户贡献的备注 1 note

up
0
yannick_duchene at yahoo dot fr
19 hours ago
May be null could be considered to be a singleton type two. In my possibly wrong understanding, PHP has three singleton types, not just two.
To Top