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 classThe 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
Identify the abstract class
Check which class the error references and confirm it is declared as abstract.
- 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
Instantiate the concrete class
Replace new AbstractClass() with new ConcreteClass() using the appropriate subclass for your use case.
Got the actual stack trace?
Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.
Explain my errorBugsly 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