MIR0601
ReadonlyPropertyAlreadyInitialized
A readonly property is being assigned a value after it has already been initialized. Readonly properties can only be assigned once, typically in the constructor.
Example
Section titled “Example”<?phpclass User { public readonly string $name;
public function __construct(string $name) { $this->name = $name; }
public function rename(string $newName): void { $this->name = $newName; // Error: readonly property already initialized }}How to fix
Section titled “How to fix”Remove the assignment or use a different design pattern:
<?phpclass User { public readonly string $name;
public function __construct(string $name) { $this->name = $name; }
// Instead of modifying, create a new instance public function withName(string $name): self { return new self($name); }}