It seems that Psalm throws an ImpureVariableerror as soon as the variable $this is encountered in pure contexts.
However, if $this is used for pure method calls (documented and verified as so), there's no "impurity" because the composition of pure functions is always pure.
I found a few tickets around this topic, so not sure if this is a duplicate, I'm sorry if so.
Some quick theory first.
Given two pure functions,
A -> B
andB -> C
, their composition,A -> B -> C
, is also pure.In PHP, we can write:
Psalm correctly understand this.
However, it does not understand this when the functions are object methods.
It seems that Psalm throws an
ImpureVariable
error as soon as the variable$this
is encountered in pure contexts.However, if
$this
is used for pure method calls (documented and verified as so), there's no "impurity" because the composition of pure functions is always pure.I know this can be avoided by using static methods, but there's much less the point in a
pure
annotation if I'm forced to use static methods anyway.