Skip to content

ReadonlyPropertyAssignment

A readonly property is assigned after the constructor.

<?php
class User {
public readonly string $name;
public function __construct(string $name) {
$this->name = $name;
}
public function rename(string $name): void {
$this->name = $name; // not allowed after construction
}
}

Remove the post-construction assignment; readonly properties can only be set once during construction.