Life

PHP 8.2 is released with read-only classes

blog cover
13.

December 2022.

The PHP team has released PHP 8.2 today with read-only classes, new stand-alone types, a new random extension, trait constants, and more:

Readonly classes

Building on PHP 8.1's read-only properties, marking a class as read-only makes every property on a class read-only and prevents the creation of dynamic properties.

1readonly class BlogData
2{
3 public string $title;
4 
5 public Status $status;
6 
7 public function __construct(string $title, Status $status)
8 {
9 $this->title = $title;
10 $this->status = $status;
11 }
12}