Tag reference
@readonly
The @readonly tag declares that a property may only be written once,
during initialization, and must not change afterwards. It is the
documentation-level equivalent of PHP’s native readonly property modifier,
used where the native modifier cannot be applied — most commonly on magic
or virtual properties exposed through __get/__set and documented with
@property rather than declared as real class members.
Grammar
"@phan-read-only" [ <Description> ]"@phpstan-readonly" [ <Description> ]"@psalm-readonly" [ <Description> ]"@readonly" [ <Description> ]Examples
/** * @property-read string $id * @readonly */class Entity {}/** * @readonly Assigned lazily on first access; kept mutable * internally. */public $identifier;Names by platform
- phan
@phan-read-only- phpstan
@phpstan-readonly- psalm
@psalm-readonly- standard
@readonly
Parsing a @readonly tag produces a ReadonlyTag instance. Being a pure
marker, it adds nothing beyond the $name and optional $description
every Tag already carries.
final class ReadonlyTag extends FlagTag {}Unlike most tags in this reference, @readonly is not part of the
PSR-19 draft or phpDocumentor’s own tag list. Psalm and PHPStan each
ship their own independent support for it — distinct from PHP 8.1’s
native readonly property modifier that inspired its name. See
Psalm’s @readonly documentation
and PHPStan’s PHPDoc basics guide.