php autoloading ai_generated true

Fatal error: Uncaught Error: Class "App\SomeClass" not found

ID: php/class-not-found

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

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
83 active

Root Cause

Class not found errors in PHP 8.3 are almost always caused by incorrect namespace declarations, missing autoload mappings, or failing to run composer dump-autoload after adding new classes.

generic

Workarounds

  1. 93% success Verify PSR-4 namespace-to-directory mapping and run composer dump-autoload
    Check that the namespace in the class file matches the autoload PSR-4 mapping in composer.json. Ensure the directory structure matches the namespace. Run 'composer dump-autoload -o' to regenerate the autoload files.
  2. 88% success Check class name and file name casing on case-sensitive filesystems
    On Linux, verify that the file name exactly matches the class name including capitalization. For example, SomeClass.php must not be named someclass.php. Rename the file to match exactly.

Dead Ends

Common approaches that don't work:

  1. Manually require_once the class file everywhere it is used 75% fail

    Creates brittle dependency chains, breaks when file paths change, and defeats the purpose of autoloading. Also fails in frameworks that expect PSR-4 autoloading.

  2. Delete vendor/ and reinstall without checking namespace casing 70% fail

    If the namespace or class name has a case mismatch with the file path (e.g., app/ vs App/), reinstalling dependencies will not fix the issue. Linux filesystems are case-sensitive.

Error Chain

Leads to:
Preceded by:
Frequently confused with: