php autoloading ai_generated true

Class 'App\Services\PaymentService' not found in vendor/composer/ClassLoader.php

ID: php/composer-autoload-not-found

Also available as: JSON · Markdown
93%Fix Rate
92%Confidence
80Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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.

generic

Workarounds

  1. 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.
  2. 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:

  1. 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.

  2. 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.

Error Chain

Leads to:
Preceded by:
Frequently confused with: