Readonly Classes
3/26
Readonly Properties
Readonly Amendments
From PHP 8.2, marking all properties as
readonly
:
<?php
*readonly* class User
{
public function __construct(public string $name) {}
}
Additionally:
•
Prevents dynamic properties from being created
•
Can't be used if there are untyped or static properties
•
Inherited classes
must
also be readonly