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.
Class not foundUncaught Error: ClassClass 'X' not found 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 installnot run on server- Namespace/
usestatement 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
- Run
composer install(andcomposer dump-autoload) - Check
usestatements and namespace declarations - Match file name case to class name exactly
- Enable the extension for built-in classes
Detailed fix by platform
PHP
composer dump-autoload -oafter adding classes; verifyautoload.psr-4in composer.json maps the namespace prefix to the right folder.
Code examples
PSR-4 mapping must match folders and case
{
"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
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
- Name — Fully qualified class name correct?
- Autoload — Does PSR-4 map it to an existing file?
- 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:
Similar errors
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 12 Oct 2026