Class 'App\Services\PaymentService' not found in vendor/composer/ClassLoader.php
ID: php/composer-autoload-not-found
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2 | active | — | — | — |
Root Cause
Composer autoload class not found errors occur when composer's generated autoloader cannot map a class name to a file. This is almost always caused by a mismatch between the PSR-4 namespace configuration in composer.json and the actual file/directory structure.
genericWorkarounds
-
94% success Fix the PSR-4 autoload mapping in composer.json and regenerate
Verify the 'autoload.psr-4' section in composer.json maps the namespace prefix to the correct directory. For example, '"App\\"': "src/"' means the App namespace maps to the src/ directory. Run 'composer dump-autoload -o' after fixing.
-
91% success Verify file and directory naming matches the namespace exactly
Check that the class file is in the correct directory and the filename matches the class name exactly (case-sensitive on Linux). For App\Services\PaymentService, the file must be at {psr4-root}/Services/PaymentService.php with the correct namespace declaration.
Dead Ends
Common approaches that don't work:
-
Deleting the entire vendor/ directory and running composer install without checking autoload config
72% fail
If the autoload PSR-4 mapping in composer.json is incorrect, reinstalling dependencies will regenerate the same broken autoloader. The issue is in the configuration, not in corrupted vendor files.
-
Adding explicit require_once statements for every class
78% fail
Bypassing the autoloader with manual require_once statements defeats the purpose of composer and creates brittle, unmaintainable dependency chains. It breaks framework conventions and will not work with dependency injection containers.