Class Not Found / Autoloader Failures
TL;DR
'Class not found' errors mean the autoloader couldn't locate the class file — usually a namespace mismatch, missing composer install, or PSR-4 misconfiguration.
Explanation
PHP loads classes on demand via autoloaders registered with spl_autoload_register(). Composer generates a PSR-4 autoloader that maps namespace prefixes to directories. Common causes of 'class not found': wrong namespace (App\Models vs App\Model), file name doesn't match class name (case-sensitive on Linux), forgot to run composer dump-autoload after adding a new file, or class is in a file not included in autoload paths in composer.json. Debug with composer dump-autoload -v to see what's mapped.
Common Misconception
✗ Class not found means the class doesn't exist — it usually means the autoloader can't find the file due to namespace/path mismatch, not a missing class.
Why It Matters
Autoloader failures are among the most common PHP errors in new developer setups and CI environments where composer install hasn't been run.
Common Mistakes
- Wrong namespace declaration — namespace doesn't match directory structure.
- File name case mismatch (UserService.php vs userservice.php) — fatal on Linux, works on macOS.
- Forgetting composer dump-autoload after adding new classes.
Code Examples
✗ Vulnerable
// File: src/Services/userService.php
namespace App\Service; // Wrong: should be App\Services
class UserService {}
✓ Fixed
// File: src/Services/UserService.php
namespace App\Services; // Matches PSR-4: App\\ => src/
class UserService {}
// composer.json:
// "autoload": {"psr-4": {"App\\\\": "src/"}}
// Run: composer dump-autoload
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
22 Mar 2026
Views
22
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Amazonbot 8
Unknown AI 4
Perplexity 4
Google 2
ChatGPT 1
Ahrefs 1
Also referenced
How they use it
crawler 17
pre-tracking 3
Related categories
⚡
DEV INTEL
Tools & Severity
🟠 High
⚙ Fix effort: Low
⚡ Quick Fix
Check namespace matches directory structure (PSR-4). File name must match class name exactly (case-sensitive). Run composer dump-autoload after adding files.
📦 Applies To
PHP 5.3+
web
cli
🔗 Prerequisites
🔍 Detection Hints
Class .* not found
Auto-detectable:
✗ No
composer
⚠ Related Problems
🤖 AI Agent
Confidence: High
False Positives: Low
✗ Manual fix
Fix: Low
Context: File