Appearance
Mutability annotations
Psalm has few annotations for mutability. They are differ by a scope they can be applied.
Scopes
class
@psalm-immutable: the same asreadonlyclasses in PHP 8.2.
methods
@psalm-mutation-free: to annotate a class method that does not mutate state (getter-like). It's not @pure as it depends on $this (class context).@psalm-external-mutation-free: to annotate a class method that does not mutate state externally of the class's scope.
properties
@readonly/@psalm-readonly: to annotate a property that can only be written to in its defining class's constructor.@psalm-allow-private-mutation: to annotate@readonlyproperties that can be mutated in a private context.@psalm-readonly-allow-private-mutation: the same as combination of@readonly+@psalm-allow-private-mutation
functions (incl. methods)
@psalm-pure: to annotate a pure function - one whose output is just a function of its input.