Skip to content

Tag reference

@property-read

The @property-read tag declares a magic property that can only be read, never written: __get is expected to handle it, but __set should reject it (or simply doesn’t exist). It is otherwise identical to @property — written on the class docblock, one line per property — and exists so that IDEs and static analyzers can flag an accidental assignment to a value that the class was never meant to accept.

Grammar

"@phan-property-read" <Type> <Variable> [ <Description> ]
"@phpstan-property-read" <Type> <Variable> [ <Description> ]
"@property-read" <Type> <Variable> [ <Description> ]
"@psalm-property-read" <Type> <Variable> [ <Description> ]

Examples

A computed value with no corresponding setter.
/**
* @property-read int $length
*/
class ImmutableString
{
public function __get(string $name): mixed { /* ... */ }
}
A read-only property with a description.
/**
* @property-read DateTimeImmutable $createdAt When the record was
* inserted.
*/
class Record {}

Names by platform

phan
@phan-property-read
phpstan
@phpstan-property-read
psalm
@psalm-property-read
standard
@property-read

Parsing a @property-read tag produces a TypedVariableTag instance exposing:

  • $type — the documented TypeNode.
  • $variable — the property’s name, without the leading $.
final class PropertyReadTag extends MagicPropertyTag
{
// Inherits `$type` (a `TypeNode`)
// and `string $variable` (required, non-null)
// from MagicPropertyTag; adds nothing of its own.
}

Use @property instead when both directions are supported, or @property-write for the mirror case of a write-only property.

Defined by the same PSR-19 §5.11 section as @property, and phpDocumentor’s own @property-read reference.