DELAPARRA
Index
Color
NL
Category: Programming paradigms

Global State

Explained by Updated

What is Global State?

Global State: Variables accessible from any procedure. Procedural code often relies on shared global state, which is its biggest weakness — unexpected mutations are hard to trace. Global state is data that any part of a program can read and change, such as global variables or static properties that act like them. It is convenient, because nothing needs to be passed around.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Global State

How is Global State used in practice?

It is also a common source of bugs. When a value changes unexpectedly, any line in the codebase could be responsible. Tests become fragile too, because one test can leave global state behind that affects the next.

What should you keep in mind with Global State?

Modern frameworks reduce the need for it with dependency injection and request-scoped services. Long-running PHP setups like Laravel Octane or queue workers make it more dangerous, because static data survives from one request or job to the next. Pass data explicitly where you can, and treat any shared mutable state as something to justify and document.

At a glance

CategoryProgramming paradigms
Explained by
Updated

More Programming paradigms terms

All terms starting with G

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.