Interfaces
An interface lists methods a class must write. A class can implement several.
Example
interface Shape { function area(): float; }
class Sq implements Shape { function __construct(private float $s) {} function area(): float { return $this->s ** 2; } }
echo (new Sq(3))->area();Result
9
Exercise
Use an interface.
class A I {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.