Class not found PHP Origin: Application & API Last updated 12 Oct 2026

PHP Fatal error: Uncaught Error: Class "X" not found

PHP couldn’t load the class — autoloading failed, the namespace is wrong, or the dependency isn’t installed.

Exact message you may see Class not foundUncaught Error: ClassClass 'X' not found
Seen on: PHP

Meaning

Modern PHP relies on Composer’s PSR-4 autoloader. The class name (with namespace) must map to a file path that exists with matching case.

Common causes

  • vendor/ missing — composer install not run on server
  • Namespace/use statement wrong
  • File name or directory case differs from class (works on macOS, fails on Linux)
  • Autoload map stale after adding classes
  • Missing PHP extension providing the class (e.g. PDO, ZipArchive)

⚡ Quick fix

  1. Run composer install (and composer dump-autoload)
  2. Check use statements and namespace declarations
  3. Match file name case to class name exactly
  4. Enable the extension for built-in classes

Detailed fix by platform

PHP

  1. composer dump-autoload -o after adding classes; verify autoload.psr-4 in composer.json maps the namespace prefix to the right folder.

Code examples

PSR-4 mapping must match folders and case

json
{
  "autoload": {
    "psr-4": { "App\\": "src/" }
  }
}

With this mapping, App\Services\Mailer must live in src/Services/Mailer.php — exact case on Linux. Run composer dump-autoload after changes.

Missing use statement

php
namespace App\Http\Controllers;

use App\Models\Invoice;          // without this line PHP looks for App\Http\Controllers\Invoice

class BillingController {
    public function show(int $id) { return Invoice::find($id); }
}

How to diagnose

  1. Name — Fully qualified class name correct?
  2. Autoload — Does PSR-4 map it to an existing file?
  3. Deploy — Is vendor/ present on the server?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Call to undefined function — PHP Fatal error: Uncaught Error: Call to undefined function (PHP)Call to undefined fun…ClassNotFoundException — java.lang.ClassNotFoundException / NoClassDefFoundError (Java)ClassNotFoundExceptionComposer conflict — Your requirements could not be resolved to an installable set of packages. (PHP)Composer conflictComposer memory — Composer: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (PHP)Composer memoryintl missing — Class "NumberFormatter" not found / The "intl" PHP extension is required (PHP)intl missingModuleNotFoundError — ModuleNotFoundError: No module named 'x' (Python)ModuleNotFoundErrorTarget class does not exist — Laravel: Target class [App\Http\Controllers\X] does not exist. (PHP)Target class does not…Class not…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.