readonly-properties
Installation
SKILL.md
Readonly Properties
When to use
- The user wants an object whose state cannot change after construction on PHP 8.1+, such as a value object or DTO.
- The user wants the engine to reject any write to a property after it is initialized, on PHP 8.1+.
- The user wants every property of a class to be immutable and reaches for a readonly class on PHP 8.2+.
When NOT to use
- Do not use readonly properties for entities whose state legitimately changes over their lifetime (e.g. an aggregate with status transitions).
- Do not use readonly properties when the target runtime is PHP 8.0 or earlier; enforce immutability with private properties and no setters instead.