🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »
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 original object to delegate the work to an instance of these classes, instead of acting on its own.

Learn more about State

Usage of the pattern in PHP

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.

State in Other Languages

Design Patterns: State in Java Design Patterns: State in C# Design Patterns: State in Python Design Patterns: State in Ruby Design Patterns: State in Swift Design Patterns: State in TypeScript