Interfaces in OOP — a practical guide to PHP interfaces with clear examples you can reuse in real projects.
OOP Tutorial Series (27/65). Prefer one article? Read the complete OOP tutorial.
Short description
Interfaces are ideal for polymorphism and dependency injection. A class can implement many interfaces.
Interface
interface Logger {
public function info(string $message): void;
}
class FileLogger implements Logger {
public function info(string $message): void { file_put_contents('app.log', $message.PHP_EOL, FILE_APPEND); }
}