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

Class Not Found / Autoloader Failures

PHP PHP 5.3+ Beginner
debt(d7/e3/b3/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no and the tool listed is composer (not a static linter). The error only surfaces at runtime when the class is actually instantiated, and the code_pattern 'Class .* not found' is a runtime fatal error, not a static analysis warning. It won't appear until the code path is exercised.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix describes a small set of checks: verify namespace matches directory structure (PSR-4), confirm file name case matches class name, and run composer dump-autoload. This is a small targeted fix within one component — not a one-liner swap but not a multi-file refactor either.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The issue is scoped to the specific class or module that has the namespace/path mismatch. Once fixed, the rest of the codebase is unaffected. It applies broadly to web and cli contexts but each instance of the problem is localised to the offending class registration.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field explicitly states: 'Class not found means the class doesn't exist — it usually means the autoloader can't find the file due to namespace/path mismatch.' This directly contradicts the obvious reading of the error message. A competent developer unfamiliar with PHP autoloading will waste significant time looking for a missing class definition rather than examining namespace/path alignment or running dump-autoload. The case-sensitivity trap (fatal on Linux, silent on macOS) compounds the confusion.

About DEBT scoring →

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 55
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 2 pings W 1 ping T 0 pings F 2 pings S 2 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 2 pings W 0 pings T 1 ping F 1 ping S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 9 ChatGPT 8 Perplexity 5 Unknown AI 4 Scrapy 4 Google 3 Ahrefs 3 SEMrush 2 Claude 1 Bing 1 Meta AI 1 PetalBot 1
crawler 38 crawler_json 1 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