Understanding ReAll relations between classes in PHPlationships Between Classes, Interfaces, Traits, and Enums in PHP

Modern PHP offers four major code structures — classes, interfaces, traits, and enums — each with its own purpose and rules. But the real power of PHP comes from how these structures can interact with each other. This page gathers all relations between classes in PHP.

If you’ve ever wondered “Can an enum use a trait?” or “Can a trait implement an interface?”, the answer lies in PHP’s keywords: extends, implements, and use. These keywords define the legal relationships between the building blocks of your code.

To make this crystal clear, here’s a matrix showing who can interact with whom — and with which keyword.

Can interact with… class interface trait enum
class extends one class(single inheritance); Or composition extends one or multiple interface use one or multiple traits ❌ Cannot extend an enum (no inheritance), can only call its cases
interface ❌ Cannot extend a class extends one or multiple interfaces ❌ Cannot use a trait ❌ Cannot implement or extend an enum
trait ❌ Cannot extend a class ❌ Cannot implement an interface useother traitsinside a trait ❌ Cannot use an enum
enum ❌ Cannot extend a class implementsone or multiple interfaces use one or multiple traits ❌ Cannot extend another enum

Key Takeaways

  • Classes are the most versatile: they can extend a class, implement interfaces, and use traits.

  • Interfaces can only extend other interfaces — nothing else.

  • Traits are like reusable code fragments. They can be used in classes and enums and even use other traits, but cannot stand alone.

  • Enums (introduced in PHP 8.1) behave like special classes: they cannot extend other classes or enums, but they can implement interfaces and use traits.