"Class "X" not found" in PHP — What It Means and How to Fix It

What the PHP error "Class "X" not found" means and how to fix it.

Published October 31, 2026

PHP cannot find the class you referenced. The file was not loaded, the namespace is wrong or Composer's autoloader does not know about it.

What it means and why it happens

Typical causes: a missing use statement, wrong namespace or path casing, forgetting to require vendor/autoload.php or an outdated autoload map.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Fatal error: Uncaught Error: Class "App\Models\User" not found

Practical examples

Code that triggers it

<?php
$u = new User();   // namespace not imported

The fix

<?php
use App\Models\User;
require __DIR__ . '/vendor/autoload.php';
$u = new User();

Refresh the autoloader

composer dump-autoload
composer dump-autoload -o   # optimised for production

Common mistakes

  • Namespace and folder name mismatch (case matters on Linux).
  • Forgetting the use statement.
  • Not running composer install on the server.

Key takeaways

  • Class not found: PHP cannot find the class you referenced.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Why does it work locally but not on Linux?

File names are case-sensitive on Linux; match the class name exactly.

How do I find which line caused Class not found?

The error message and stack trace show the file and line; start there and work backwards.

More PHP articles