Interfaces and Abstract Classes in PHP
In this post we will discuss what exactly is interface & abstract class. Basic differences between them and when to use what!.
Interface
An interface is a contract: the person writing the interface says “I will only accept things looking that way”, and the person using the interface says “OK, the class I write will look that way”.
An interface is an empty shell, there are only the signatures (name / params / return type) of the methods. The methods do not contain anything. The interface can’t do anything. It’s just a pattern.
<?php
// I say all motor vehicles should look like that :
interface MotorVehicle {
public function run();
public function getFuel();
}
// another developer complies and write vehicle looking that way
class Car implements MotoVehicle {
public $fuel;
public function run() {
print
Geek Speak