Recall & Review
beginner
What is an enum backed value in PHP?
An enum backed value in PHP is a way to assign a specific scalar value (like int or string) to each enum case, allowing the enum to hold and return that value.
Click to reveal answer
beginner
How do you declare a backed enum with string values in PHP?
Use the syntax:
enum Status: string { case Active = 'active'; case Inactive = 'inactive'; } where : string declares the enum as backed by strings.Click to reveal answer
intermediate
What happens if you try to assign a non-scalar value to a backed enum case?
PHP will throw a fatal error because backed enum cases must have scalar values (int or string) only.
Click to reveal answer
beginner
How can you get the backed value of an enum case in PHP?
You can access the backed value using the
->value property, for example: Status::Active->value returns 'active'.Click to reveal answer
intermediate
Can backed enums have methods in PHP?
Yes, backed enums can have methods just like regular enums, allowing you to add behavior related to the enum cases.
Click to reveal answer
Which scalar types can be used for backed enum values in PHP?
✗ Incorrect
Backed enums in PHP only support int and string scalar types for their values.
How do you declare an enum backed by integers in PHP?
✗ Incorrect
You declare an int backed enum by specifying ': int' after the enum name and assigning integer values to cases.
What will
Status::Active->value return if enum Status: string { case Active = 'active'; }?✗ Incorrect
The ->value property returns the backed value assigned to the enum case, which is 'active'.
Can you assign a float value to a backed enum case in PHP?
✗ Incorrect
PHP backed enums only support int and string scalar types, float is not allowed.
What will happen if you try to assign an array as a backed enum value?
✗ Incorrect
Backed enum values must be scalar (int or string). Assigning an array causes a fatal error.
Explain what a backed enum is and how you use it in PHP.
Think about enums that hold specific values like numbers or words.
You got /4 concepts.
Describe the rules and limitations for values assigned to backed enum cases in PHP.
Consider what types PHP allows for enum case values.
You got /4 concepts.