Source Code:
(back to article)
<?php // Example 1 interface Animal { public function makeSound(); } class Dog implements Animal { public function makeSound() { echo "Woof!"; } } $dog = new Dog(); $dog->makeSound(); // Output: Woof! // Example 2 interface Shape { public function getArea(); } class Circle implements Shape { private $radius; public function __construct($radius) { $this->radius = $radius; } public function getArea() { return pi() * pow($this->radius, 2); } } $circle = new Circle(5); echo $circle->getArea(); // Output: 78.539816339745
Result:
Report an issue