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

What is an abstract class in PHP, and how does it differ from a regular class and from an interface?

Beginner

Answer

An abstract class cannot be instantiated directly and is meant to be extended by other classes, and unlike an interface, it can contain both fully implemented methods that subclasses inherit as is, as well as abstract methods that have no implementation and must be provided by any concrete subclass, making abstract classes useful when you want to share some common implementation logic across related classes while still requiring each subclass to implement certain specific behaviors of their own.
abstract class Shape {
    abstract public function area(): float;
    public function describe(): string {
        return 'This shape has an area of ' . $this->area();
    }
}
Real-world example A shape hierarchy uses an abstract Shape class that provides a shared describe method usable by every subclass, while still requiring each specific shape, such as Circle or Rectangle, to implement its own area calculation method.

Common follow-ups: Can an abstract class implement an interface?;Why might you choose an abstract class over an interface for a specific design situation?