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

Dead Condition

quality PHP 5.0+ Intermediate
debt(d3/e1/b1/t5)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). PHPStan, Psalm, and Rector (all listed in detection_hints.tools) catch dead conditions automatically at moderate levels. PHPStan flags these at level 6+, making detection fairly routine with standard static analysis tooling in PHP projects.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix explicitly states 'Remove conditions that are always true or false' — this is typically a single-line deletion or simplification of the conditional expression, requiring no architectural changes.

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

Closest to 'minimal commitment' (b1). A dead condition is a localized bug in a single conditional statement. It doesn't impose any structural weight on the codebase — once fixed, there's no ongoing maintenance cost or gravitational pull on future development.

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

Closest to 'notable trap' (t5). The misconception field reveals the trap: developers assume dead conditions are 'harmless since they don't affect runtime' but they actually 'indicate a logic error somewhere.' The why_it_matters section shows the serious case — a dead condition like 'if ($isAdmin || true)' silently disables security checks. This is a documented gotcha that experienced devs learn, but the 'obvious' assumption that unreachable code is merely wasteful rather than symptomatic of a bug is a meaningful cognitive trap.

About DEBT scoring →

Also Known As

always true condition always false branch tautology contradiction

TL;DR

A boolean condition that is always true or always false due to logic errors, making the branch either always execute or never execute.

Explanation

Dead conditions waste cognitive overhead — readers reason about a branch that can never change the outcome. They typically arise from: contradictory conditions (if $x > 5 && $x < 3), type coercion surprises, copy-paste errors, or refactoring that left conditions stale. Static analysers (PHPStan level 6+, Psalm) detect many dead conditions automatically. The fix is to remove the dead branch and document why the condition was wrong.

Common Misconception

Dead conditions are harmless since they don't affect runtime — they indicate a logic error somewhere; what the developer intended was almost certainly different from what was written.

Why It Matters

A dead condition on a security check (if ($isAdmin || true)) silently disables the check — dead conditions in auth or validation paths are critical bugs, not just style issues.

Common Mistakes

  • Checking a value against a range it can never satisfy: if ($percent > 100 && $percent < 0).
  • Checking a typed parameter for a condition its type makes impossible: if (is_string($str) && !is_string($str)).
  • Post-loop conditions that are always true after the loop has terminated.
  • Copy-paste conditions: checking the same variable twice with the same comparator.

Code Examples

✗ Vulnerable
// Dead conditions — always true or always false:
function isValidPercent(int $p): bool {
    // int cannot be both > 100 AND < 0 simultaneously:
    if ($p > 100 && $p < 0) { // Always false — dead branch
        return false;
    }
    return true; // Always reached
}

// Always true — $items is always an array here:
$items = getItems(); // returns array
if (is_array($items) || count($items) > 0) { /* always executes */ }
✓ Fixed
// Corrected conditions — actually reachable:
function isValidPercent(int $p): bool {
    if ($p < 0 || $p > 100) { // OR not AND — correct range check
        return false;
    }
    return true;
}

// Simplified — remove dead branch:
$items = getItems();
if (count($items) > 0) { /* meaningful check */ }

Added 16 Mar 2026
Edited 5 Apr 2026
Views 26
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 2 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 1 ping 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 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 8 Perplexity 6 Google 4 Unknown AI 2 Ahrefs 2 Majestic 1 ChatGPT 1
crawler 23 crawler_json 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Remove conditions that are always true or false — they add complexity without adding safety; PHPStan will flag many of these automatically at level 6+
📦 Applies To
PHP 5.0+ any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
if ($x !== null) where $x has non-nullable type; if (true) or if (false) branches; condition always evaluating same way due to type constraint
Auto-detectable: ✓ Yes phpstan psalm rector
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✓ Auto-fixable Fix: Low Context: Function
CWE-570 CWE-571

✓ schema.org compliant