Category: Object-oriented programming (OOP)

What is different between abstract class and interface in PHP?

1) – For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.
– For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces.

2) – The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.
– All methods declared in an interface must be public.

3) – Abstract class can contain variables and concrete methods.
– Interfaces cannot contain variables and concrete methods except constants.

4) – A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class.
– A class can implement many interfaces and Multiple interface inheritance is possible.

5) – Abstract class can contains constructor
– Interfaces cannot contain constructor

6) – Only complete member of abstact class can be static
– Member of interface can not be static