Recall & Review
beginner
What are interface constants in PHP?
Interface constants are fixed values defined inside an interface. They cannot be changed and are automatically public.
Click to reveal answer
beginner
How do you define a constant inside a PHP interface?
Use the <code>const</code> keyword followed by the name and value, for example: <code>const STATUS = 'active';</code>Click to reveal answer
intermediate
Can interface constants be overridden in classes that implement the interface?
No, interface constants cannot be changed or overridden by implementing classes. They remain fixed as defined in the interface.
Click to reveal answer
beginner
How do you access an interface constant from outside the interface?
Use the interface name followed by the scope resolution operator
:: and the constant name, like InterfaceName::CONSTANT_NAME.Click to reveal answer
intermediate
Why use constants in interfaces instead of class constants?Interface constants provide a way to define fixed values that all implementing classes share, ensuring consistency and avoiding duplication.
Click to reveal answer
Which keyword is used to declare a constant inside a PHP interface?
✗ Incorrect
Constants inside interfaces are declared using the
const keyword.Can a class that implements an interface change the value of an interface constant?
✗ Incorrect
Interface constants are fixed and cannot be overridden or changed by implementing classes.
How do you access an interface constant named STATUS in interface UserInterface?
✗ Incorrect
Use the interface name followed by
:: and the constant name to access it.What visibility do interface constants have by default?
✗ Incorrect
Interface constants are always public and cannot have other visibility modifiers.
Why might you use constants in an interface?
✗ Incorrect
Constants in interfaces provide fixed values that all implementing classes share for consistency.
Explain what interface constants are and how they are used in PHP.
Think about fixed values shared by all classes implementing the interface.
You got /5 concepts.
Describe how to access and why to use constants defined in an interface.
Consider the benefit of having common values for all implementers.
You got /4 concepts.