Skip to content

MIR1706

ImpureStaticPropertyAssignment

An impure function assigns to a static property, which introduces side effects that can make code harder to reason about and test.

<?php
class Counter {
public static $count = 0;
public static function increment(): void {
self::$count++; // Static property modification in function
}
}

Consider using instance properties or dependency injection instead of static properties:

<?php
class Counter {
private int $count = 0;
public function increment(): void {
$this->count++;
}
public function getCount(): int {
return $this->count;
}
}