In this example class
Circle
implements
CircleAbstract
interface.
Therefore it must define
getArea()
and
getPerimeter()
methods
interface CircleAbstract {
// Force Extending class to define these methods
function getArea();
function getPerimeter();
}
class Circle implements CircleAbstract {
static $PI = 3.1415926536;
public $radius;
public function __construct($radius) {
$this->radius = $radius;
}
public function getPI() {
return self::$PI;
}
public function getArea() {
return pow($this->radius, 2) * self::$PI;
}
public function getDiameter() {
return $this->radius * 2;
}
public function getPerimeter() {
return $this->radius * 2 * self::$PI;
}
}
$circle1 = new Circle(5);
echo "\nPI: " . $circle1->getPI();
echo "\nArea: " . $circle1->getArea();
echo "\nDiameter: " . $circle1->getDiameter();
echo "\nPerimeter: " . $circle1->getPerimeter();