May 16, 2024
Breaking News

PHP 8.1 is Here – Laravel News

npressfetimg-703.png

The PHP team announced the release of PHP 8.1 yesterday:

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.......

Source: https://laravel-news.com/php-8-1-0