Skip to content

Tag reference

@immutable

The @immutable tag declares a class as immutable, meaning none of its state can change after construction. Real enforcement exists independently in Psalm (@psalm-immutable), PHPStan (@phpstan-immutable) and Phan (@phan-immutable).

Grammar

"@immutable" [ <Description> ]
"@phan-immutable" [ <Description> ]
"@phpstan-immutable" [ <Description> ]
"@psalm-immutable" [ <Description> ]

Examples

A value object whose state is fixed once built.
/**
* @immutable
*/
final class Money {}
With a description explaining the guarantee.
/**
* @immutable Every "with*" method returns a new instance.
*/

Names by platform

phan
@phan-immutable
phpstan
@phpstan-immutable
psalm
@psalm-immutable
standard
@immutable

Parsing an @immutable tag produces an ImmutableTag instance. Being a pure marker, it adds nothing beyond the $name and optional $description every Tag already carries.

final class ImmutableTag extends FlagTag {}