Class Not Found

Fatal error: Uncaught Error: Class 'App\Service\UserService' not found

Quick Answer

PHP cannot find the specified class. Verify the namespace, file path, and autoloader configuration match. Run composer dump-autoload if using Composer.

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. 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. 2

    Check the use statement

    Ensure you have the correct use statement at the top of the file importing the class.

  3. 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.

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