Skip to content

WS004 · Mutable singleton

Default severity: MEDIUM · Framework: Any

A singleton is created once and then reused. Under a persistent worker “once” means once per worker process, so every request shares the same instance and everything written into it.

  • Register the class in your container instead, so its lifetime is controlled by the framework.
  • Keep the shared instance immutable: readonly properties set in the constructor only.
  • If it must hold per-request values, resolve a fresh instance per request (Laravel: scoped()).
Terminal window
vendor/bin/worker-safety rules WS004

Use a targeted suppression or a baseline only after reviewing the value’s origin and lifetime. Changing an assignment elsewhere may not invalidate an existing property-level suppression.