Source: www.amitmerchant.com

Readonly classes in PHP 8.2
When https://www.amitmerchant.com/readonly-properties-are-coming-in-php-81/ were introduced in PHP 8.1, it has provided a legitimate way of making class properties truly “readonly”. Before that, developers used to replicate this behavior by making the intended property private so that it kind of becomes “readonly”. class Book { private $author; public function __construct( string $author ) { $this->author = $author; }} $book = new Book('Ruskin Bond'); $book->author = 'J.

You can call readonly classes as an extension to the readonly properties where once you make a class as readonly, it will implicitly mark all instance properties of a class as readonly.

// Fatal error: Non-readonly class Magazine cannot // extend readonly class Book class Book {} readonly class Magazine extends Book {}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners