Recall & Review
beginner
What is an interface in PHP?
An interface in PHP is a contract that defines methods a class must implement, without providing the method bodies.Click to reveal answer
beginner
How do you declare an interface in PHP?
Use the
interface keyword followed by the interface name and method signatures inside curly braces.Click to reveal answer
beginner
What keyword is used by a class to implement an interface?The <code>implements</code> keyword is used by a class to promise it will provide all methods defined in the interface.Click to reveal answer
intermediate
Can a class implement multiple interfaces in PHP?Yes, a class can implement multiple interfaces by listing them separated by commas after the <code>implements</code> keyword.Click to reveal answer
intermediate
What happens if a class does not implement all methods of an interface?PHP will throw a fatal error because the class breaks the contract defined by the interface.Click to reveal answer
Which keyword is used to declare an interface in PHP?
✗ Incorrect
The
interface keyword declares an interface.How does a class promise to follow an interface's contract?
✗ Incorrect
Classes use
implements to promise to provide all interface methods.Can an interface contain method bodies in PHP?
✗ Incorrect
Interfaces only declare method signatures without bodies.
What happens if a class misses implementing a method from an interface?
✗ Incorrect
PHP requires all interface methods to be implemented; otherwise, it throws a fatal error.
How can a class implement multiple interfaces?
✗ Incorrect
Multiple interfaces are listed separated by commas after
implements.Explain what an interface is in PHP and how a class uses it.
Think of an interface as a promise a class makes.
You got /4 concepts.
Describe what happens if a class does not implement all methods from an interface it declares to implement.
PHP is strict about interfaces.
You got /4 concepts.