Why This Happens
PHP does not allow two classes with the same fully qualified name. This error occurs when a file defining a class is included multiple times, or when two files in different locations define the same class. It can also happen with misconfigured autoloaders that map multiple files to the same class.
The Problem
require 'src/Entity/User.php';
require 'src/Entity/User.php'; // Loaded againThe Fix
require_once 'src/Entity/User.php';
// Or better: use Composer autoloading and never require manuallyStep-by-Step Fix
- 1
Find both declarations
The error tells you where the class was previously declared. Search your codebase for duplicate class definitions with the same name.
- 2
Use require_once
Replace all require and include with require_once and include_once for files that define classes.
- 3
Switch to autoloading
Use Composer's PSR-4 autoloading to automatically load classes based on namespace and directory structure, eliminating manual includes.
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