The PHP team announced the release of PHP 8.1 yesterday:
? PHP 8.1 is released!
? Read all about it at: https://t.co/ToeHc3YGau
♻️ Migration Guide: https://t.co/BVVZ7lSXd1
? Many thanks to the contributors for everything they implemented, and the RMs to get this amazing new version released!
❓ What’s your favourite new feature?
— php.net (@official_php) November 25, 2021
According to the announcement, here is a list of the main features for PHP 8.1:
Enumerations
PHP 8.1 supports Enumerations (Enums) natively, providing a rich api for defining and working with Enums:
1enum Status
2{
3 case Draft;
4 case Published;
5 case Archived;
6}
7function acceptStatus(Status $status) {...}
Read-only Properties
Read-only properties cannot be changed after they are initialized. You can be confident that your data classes are consistent. PHP 8.1 can reduce boilerplate by defining public properties the author does not intend to change, instead of private properties accessible via “getter” methods:
1class BlogData
2{
3 public readonly Status $status;
4
5 public function __construct(Status $status)
6 {
7 $this->status = $status;
8 }
9}
Intersection Types
You can use intersection types when needing to satisfy multiple constraints at the same time:
1.......