SyntaxStudy
Sign Up
PHP Implementing Multiple Interfaces
PHP Intermediate 5 min read

Implementing Multiple Interfaces

Multiple Interfaces

A class can implement multiple interfaces, separated by commas. This is how PHP achieves multiple-inheritance behavior.

Example
<?php
interface Printable {
    public function print(): void;
}

interface Exportable {
    public function toArray(): array;
    public function toJson(): string;
}

interface Cacheable {
    public function getCacheKey(): string;
}

class Invoice implements Printable, Exportable, Cacheable {
    public function print(): void { echo "Invoice #1"; }
    public function toArray(): array { return ["id" => 1]; }
    public function toJson(): string { return json_encode($this->toArray()); }
    public function getCacheKey(): string { return "invoice:1"; }
}
Pro Tip

A class can implement as many interfaces as needed — combine multiple small interfaces rather than one large one (Interface Segregation Principle).