← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Class Not Found / Autoloader Failures

php PHP 5.3+ Beginner

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

Added 22 Mar 2026
Views 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 3 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 8 Unknown AI 4 Perplexity 4 Google 2 ChatGPT 1 Ahrefs 1
crawler 17 pre-tracking 3
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

✓ schema.org compliant