Dead Code
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);
}
}
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
32
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Perplexity 8
Amazonbot 8
Ahrefs 7
Google 2
Majestic 1
Also referenced
How they use it
crawler 25
crawler_json 1
Related categories
⚡
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