Interface Inheritance
Interfaces can extend other interfaces with extends. The child interface inherits all methods from the parent and can add more.
Interfaces can extend other interfaces with extends. The child interface inherits all methods from the parent and can add more.
<?php
interface Readable {
public function read(): string;
}
interface Writable {
public function write(string $data): void;
}
// ReadWrite extends both
interface ReadWrite extends Readable, Writable {
public function seek(int $position): void;
}
class FileStream implements ReadWrite {
public function read(): string { return "data"; }
public function write(string $data): void {}
public function seek(int $position): void {}
}
Interface inheritance lets you build layered contracts — start with narrow interfaces and compose them into broader ones.