Cannot Instantiate Abstract Class

Fatal error: Uncaught Error: Cannot instantiate abstract class App\Base\AbstractRepository

Quick Answer

You cannot create an instance of an abstract class with new. Create a concrete class that extends the abstract class and instantiate that instead.

Why This Happens

Abstract classes are designed to be extended, not instantiated directly. They serve as base classes that define a contract for subclasses. If you try to use new on an abstract class, PHP throws this error. You need to create or use a concrete subclass.

The Problem

abstract class BaseRepository {
    abstract public function findAll(): array;
}
$repo = new BaseRepository(); // Cannot instantiate abstract class

The Fix

abstract class BaseRepository {
    abstract public function findAll(): array;
}

class UserRepository extends BaseRepository {
    public function findAll(): array {
        return ['Alice', 'Bob'];
    }
}
$repo = new UserRepository();

Step-by-Step Fix

  1. 1

    Identify the abstract class

    Check which class the error references and confirm it is declared as abstract.

  2. 2

    Find or create a concrete subclass

    Look for existing classes that extend the abstract class, or create a new one that implements all abstract methods.

  3. 3

    Instantiate the concrete class

    Replace new AbstractClass() with new ConcreteClass() using the appropriate subclass for your use case.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free