Autumn SALE
State

State in PHP

State is a behavioral design pattern that allows an object to change the behavior when its internal state changes.

The pattern extracts state-related behaviors into separate state classes and forces the original object to delegate the work to an instance of these classes, instead of acting on its own.

Complexity:

Popularity:

Usage examples: The State pattern is occasionally used in PHP for turning large and cumbersome state machines based on switch operators into objects.

Identification: State pattern can be recognized by methods that change their behavior depending on the objects’ state, controlled externally.

State in Other Languages

State in C# State in C++ State in Go State in Java State in Python State in Ruby State in Rust State in Swift State in TypeScript