What are PHP 8.1 enums?
Why Interviewers Ask This
This question targets practical, hands-on experience with PHP. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
Enums (PHP 8.1) are a first-class way to define a type that has a fixed set of possible values. A pure enum has only case names: enum Status { case Active; case Inactive; case Pending; }. A backed enum associates each case with a scalar value: enum Color: string { case Red = "red"; case Blue = "blue"; }. Access cases as singletons: Status::Active. Backed enums can be created from a value: Color::from("red") (throws on invalid) or Color::tryFrom("red") (returns null). Enums can implement interfaces, have methods, and use constants. They replace the common pattern of class constants for representing finite sets of values.
Pro Tip
This topic has PHP-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.