Mutable global state (ARCH7187)
Key php.quality.mutable-global-state · Severity warning · Category quality
Mutable global or static state creates hidden dependencies, breaks testability, and can leak across requests. Move the state into instances or make it constant.
Incorrect
Section titled “Incorrect”<?phpclass Config{ public static array $settings = [];}
Config::$settings['debug'] = true;Correct
Section titled “Correct”<?phpfinal class Config{ public function __construct(private readonly array $settings) {}
public function get(string $key): mixed { return $this->settings[$key] ?? null; }}Move shared state into an injected instance, or make it immutable (readonly).