Differences Between Implements and Extends
Now, let’s summarize the key differences between implements
and extends
:
Parameters | Implements |
Extends |
---|---|---|
Purpose | Implements interfaces | Extends a class |
Syntax | class MyClass implements MyInterface |
class ChildClass extends ParentClass |
Inheritance | No inheritance from the interface | Inheriting properties and methods from the parent class |
Multiple Usage | Can implement multiple interfaces | Can only extend one class |
Abstract Classes | Can implement abstract classes | Can only extend concrete (non-abstract) classes |
Code Reusability | Promotes code reusability through interface implementation | Promotes code reusability through class inheritance |
What is the difference between implements and extends in PHP ?
PHP facilitates two keywords, i.e. the implements
and extends
keywords, which can be used in the context of class inheritance and interface implementation. While both keywords are related to the concept of Object-Oriented Programming, they serve different purposes.