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

Dead Code

Code Quality PHP 5.0+ Beginner
debt(d3/e1/b3/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). PHPStan and Psalm, listed in detection_hints.tools, catch unreachable code after return/throw and unused private methods at default or moderate strictness levels. While not always enabled by default in projects, these are standard PHP static analysis tools that flag dead code patterns readily.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicit: 'Delete it.' Removing dead code is pure deletion—no replacement logic needed, no dependencies to update. Git preserves history if rollback is ever needed.

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

Closest to 'localised tax' (b3). Dead code imposes cognitive load on maintainers who must read and reason about code that does nothing. However, since it doesn't execute, it doesn't create runtime dependencies or architectural constraints. The burden is real but contained—each piece of dead code affects comprehension in its local area rather than shaping system architecture.

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

Closest to 'notable trap' (t5). The misconception field directly states the trap: developers believe 'dead code is harmless since it never runs.' This is a documented gotcha that experienced developers eventually learn—dead code misleads maintainers, inflates cognitive load, can contain old vulnerabilities, and may be accidentally re-enabled during merges. The intuition that non-executing code is cost-free is wrong but not catastrophically so.

About DEBT scoring →

Also Known As

unreachable code unused code zombie code

TL;DR

Code that can never be executed — unreachable after a return, or inside a condition that is always false.

Explanation

Dead code increases the cognitive load of reading code without providing any value. It can arise from if(false) conditions left from debugging, code below an unconditional return, or logic that was superseded but never removed. Dead code is confusing because readers try to understand why it's there. Worse, if a bug exists in dead code, it may be noticed and "fixed" — causing it to become live and introduce a regression. Remove dead code; source control preserves the history.

Common Misconception

Dead code is harmless since it never runs. Dead code misleads maintainers into thinking functionality exists, inflates cognitive load, can contain old vulnerabilities, and is occasionally accidentally re-enabled during merges.

Why It Matters

Dead code misleads maintainers into believing functionality exists, adds to cognitive load, and can mask live bugs when execution paths are more complex than they appear.

Common Mistakes

  • Leaving commented-out code in version control — use git; if it's commented out, delete it.
  • Unreachable code after return/throw that static analysis would catch if it were run.
  • Keeping old API endpoints 'just in case' without deprecation notices or removal timelines.
  • Private methods that are never called — IDEs flag these but warnings are often ignored.

Code Examples

💡 Note
PHPStan level 4+ will report unreachable code. Delete it — git history preserves it if you ever need it back.
✗ Vulnerable
function processOrder(Order $o): void {
    if ($o->isPaid()) {
        return;
    }
    // This block can never run for a paid order:
    $this->chargeCard($o);  // dead
    $this->sendReceipt($o); // dead
}
✓ Fixed
function processOrder(Order $o): void {
    if ($o->isPaid()) {
        return;
    }
    $this->chargeCard($o);
    $this->sendReceipt($o);
}
// Or restructure so all paths are live:
function processOrder(Order $o): void {
    if (!$o->isPaid()) {
        $this->chargeCard($o);
        $this->sendReceipt($o);
    }
}

Added 15 Mar 2026
Edited 22 Mar 2026
Views 62
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 3 pings F 0 pings S 4 pings S 4 pings M 1 ping T 2 pings W 0 pings T 1 ping F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Scrapy 15 Amazonbot 9 Ahrefs 9 Perplexity 8 Google 4 Claude 2 Bing 2 ChatGPT 2 Majestic 1 Meta AI 1 PetalBot 1
crawler 50 crawler_json 4
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Delete it — dead code is not documentation, it is noise; git history preserves it if needed
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Unreachable code after return/throw, commented-out code blocks, unused private methods
Auto-detectable: ✓ Yes phpstan psalm rector
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✓ Auto-fixable Fix: Low Context: Function


✓ schema.org compliant