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 {}