Readonly Classes
8/34
Readonly Properties
No Title Text for this slide yet
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