PHP Fatal error: Class "X" not found - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

PHP Fatal error: Class "X" not found
====================================

### [\#PHP](https://rocketeersapp.com/knowledge/php)

This fatal error means PHP could not load a class you referenced. Almost always a namespace mismatch, a wrong file name, or an autoloader that needs regenerating.

 Published by [Mark van Eijk](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Check the namespace matches the path](#content-check-the-namespace-matches-the-path)
5. [Import the class](#content-import-the-class)
6. [Regenerate the autoloader](#content-regenerate-the-autoloader)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

 ```
PHP Fatal error: Uncaught Error: Class "App\Services\Invoice" not found

```

PHP tried to use a class and couldn't find a definition for it. With Composer's PSR-4 autoloading, the class name and namespace must map exactly to a file on disk, and any mismatch breaks that lookup.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

- The **namespace** declared in the file doesn't match its folder.
- The **file name** doesn't match the class name (PSR-4 is case-sensitive, and so is Linux).
- You forgot a `use` statement, so PHP looks for the class in the current namespace.
- The class is new and the autoloader hasn't been regenerated.
- A typo in the class name.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-check-the-namespace-matches-the-path "Permalink")Check the namespace matches the path

Under PSR-4, `App\Services\Invoice` must live at `app/Services/Invoice.php` and declare:

 ```
namespace App\Services;

class Invoice
{
    // ...
}

```

The file name (`Invoice.php`) must match the class name exactly, including case. This works on macOS (case-insensitive filesystem) and then breaks on a Linux server, a very common "works locally, 500 in production" trap.

### [\#](#content-import-the-class "Permalink")Import the class

If the class is in another namespace, add a `use` statement at the top of the file:

 ```
use App\Services\Invoice;

$invoice = new Invoice();

```

### [\#](#content-regenerate-the-autoloader "Permalink")Regenerate the autoloader

If the class genuinely exists and is named correctly, Composer's autoload map may be stale:

 ```
composer dump-autoload

```

For framework classes resolved through the container (controllers, etc.), the symptom is slightly different, see [Target class does not exist in Laravel](/target-class-does-not-exist-laravel).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#PHP](https://rocketeersapp.com/knowledge/php)

- [How to run PHP files](https://rocketeersapp.com/knowledge/run-php-files)
- [PHP file upload exceeds upload\_max\_filesize](https://rocketeersapp.com/knowledge/php-file-upload-exceeds-upload-max-filesize)
- [PHP Warning: Undefined array key](https://rocketeersapp.com/knowledge/undefined-array-key-php)
- [PHP Fatal error: Allowed memory size exhausted](https://rocketeersapp.com/knowledge/php-allowed-memory-size-exhausted)
- [PHP: Call to a member function on null](https://rocketeersapp.com/knowledge/call-to-a-member-function-on-null)
- [Composer out of memory (allowed memory size exhausted)](https://rocketeersapp.com/knowledge/composer-out-of-memory-allowed-memory-size-exhausted)

 [View all 11 articles →](https://rocketeersapp.com/knowledge/php)
