Recall & Review
beginner
What is an interface in PHP?
An interface defines a contract with method signatures but no method bodies. Classes that implement the interface must provide the method implementations.
Click to reveal answer
beginner
What is an abstract class in PHP?
An abstract class can have both method signatures (abstract methods) and method bodies. It cannot be instantiated directly and is meant to be extended by other classes.Click to reveal answer
beginner
What is a trait in PHP?
A trait is a reusable set of methods that can be included in multiple classes to share functionality without using inheritance.
Click to reveal answer
beginner
Can a PHP class implement multiple interfaces?Yes, a PHP class can implement multiple interfaces, allowing it to follow multiple contracts.Click to reveal answer
beginner
Can a PHP class use multiple traits?Yes, a PHP class can use multiple traits to include different sets of reusable methods.Click to reveal answer
Which of the following can contain method implementations in PHP?
✗ Incorrect
Abstract classes and traits can contain method implementations, while interfaces only declare method signatures.
Can a PHP interface have properties?
✗ Incorrect
Interfaces cannot have properties; they only declare method signatures.
Which keyword is used to include a trait in a PHP class?
✗ Incorrect
The 'use' keyword is used inside a class to include a trait.
Can a PHP class extend multiple abstract classes?
✗ Incorrect
PHP supports only single inheritance, so a class can extend only one abstract class.
What is the main purpose of traits in PHP?
✗ Incorrect
Traits allow sharing reusable methods across classes without using inheritance.
Explain the differences between interfaces, abstract classes, and traits in PHP.
Think about what each one can contain and how they are used in classes.
You got /6 concepts.
When would you choose to use a trait instead of an abstract class or interface in PHP?
Consider code reuse and inheritance limitations.
You got /4 concepts.