PHP: Interface vs Abstract Class vs Trait
Here is a comparison between Interface, Abstract class, and Trait in PHP. Let’s take a look at that side-by-side comparison in a table.
Here is a comparison between Interface, Abstract class, and Trait in PHP. Let’s take a look at that side-by-side comparison in a table.
An Abstract class is a partially implemented class, as the abstract methods(in the class) do not contain their definition. Those methods are defined in the class that extends the Abstract class.
Interfaces are contract that ensures the availability of methods/actions that an object must contain. By implementing an interface, a class agrees to contain the definitions of the methods declared in the interface. Interfaces have just the declaration/signature of the method, and the classes(that implement the interface) must have the definition of those methods.