Why This Happens
This fatal error occurs when PHP tries to instantiate or reference a class that has not been loaded. Common causes include incorrect namespace declarations, missing use statements, typos in class names, or a misconfigured autoloader that does not map the namespace to the correct directory.
The Problem
// File: src/Controller/UserController.php
namespace App\Controller;
class UserController {
public function index() {
$service = new UserService(); // Missing use statement
}
}The Fix
namespace App\Controller;
use App\Service\UserService;
class UserController {
public function index() {
$service = new UserService();
}
}Step-by-Step Fix
- 1
Verify the class name and namespace
Check that the fully qualified class name in the error matches the namespace declaration and class name in the source file.
- 2
Check the use statement
Ensure you have the correct use statement at the top of the file importing the class.
- 3
Rebuild the autoloader
Run composer dump-autoload to regenerate the autoload mappings, and verify composer.json autoload section maps the namespace to the correct directory.
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