Multiple Inheritance — a practical guide to multiple inheritance PHP with clear examples you can reuse in real projects.
OOP Tutorial Series (21/65). Prefer one article? Read the complete OOP tutorial.
Short description
PHP does not allow extending multiple classes. Implement multiple interfaces and use traits for shared code.
Interfaces + trait
interface Loggable { public function log(string $msg): void; }
interface Cacheable { public function cacheKey(): string; }
trait WritesLog {
public function log(string $msg): void { echo $msg; }
}
class Report implements Loggable, Cacheable {
use WritesLog;
public function cacheKey(): string { return 'report'; }
}