Back to results for “OOP & Classes”
PHP › Interfaces & Abstract Classes

Can an interface extend another interface in PHP, and how does this let you build more specific contracts on top of a more general one?

Intermediate

Answer

Yes, an interface can extend one or more other interfaces using the extends keyword, meaning any class implementing the more specific extended interface must also fulfill the requirements of the original, more general interface it extends, letting you build up increasingly specific contracts in layers, such as a base Comparable interface extended by a more specific SortableCollection interface that adds additional required methods on top.
interface Comparable {
    public function compareTo($other): int;
}
interface Sortable extends Comparable {
    public function getSortKey(): mixed;
}
Real-world example A collections library defines a base Comparable interface, then a more specific Sortable interface extending it, letting classes implementing Sortable automatically also satisfy the more general Comparable contract without repeating that method's signature.

Common follow-ups: Can an interface extend multiple other interfaces at the same time?;How is extending an interface different from a class implementing multiple interfaces?