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

Unused Function

Code Quality PHP 7.0+ Beginner
debt(d5/e1/b3/t3)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list phpstan, psalm, and php-dead-code — all specialist static analysis tools rather than default linters. The quick_fix notes PHPStan catches unused private methods at level 6+, but public methods require more careful analysis. This firmly places detection at the specialist-tool tier rather than default linter (d3) or review-only (d7).

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is simply deleting the dead function — a single removal action, often in one file. The common_mistakes note that git history preserves old methods so there is no recovery risk. No refactor is needed; the fix is pure deletion.

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

Closest to 'localised tax' (b3). Unused functions impose a reading and maintenance tax on the files or classes they inhabit, misdirecting developers who encounter them. However, the burden is localised — unused functions in one module do not structurally constrain the rest of the codebase. The applies_to scope covers web/cli/queue contexts but each dead function's tax is self-contained rather than cross-cutting.

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

Closest to 'minor surprise (one edge case)' (t3). The misconception is that unused methods are fully safe because they never execute. The subtle trap is that they can be invoked via dynamic dispatch or reflection, and they mislead readers into studying or wiring in dead code incorrectly. This is a real but documented and relatively understandable gotcha, not a deep contradiction of developer intuition.

About DEBT scoring →

Also Known As

dead method unused method unreferenced function

TL;DR

A function or method that is defined but never called — dead code that increases maintenance burden and confuses readers about what is part of the active API.

Explanation

Unused private methods are detectable by static analysis and have no legitimate use — remove them. Unused public methods are harder because they may be called dynamically or from outside the codebase, but any that are confirmed unused should also be removed. Dead methods stay in codebases because developers are afraid to delete them ('someone might need it') — version control is the safety net; delete confidently. YAGNI applies: You Aren't Gonna Need It.

Common Misconception

Keeping unused methods is safe since they do not execute — they add noise, misdirect readers, and may be accidentally called via dynamic dispatch or reflection.

Why It Matters

Unused functions create false impressions of functionality — a reader spends time understanding code that is never used, or a developer 'discovers' the dead method and wires it in incorrectly.

Common Mistakes

  • Keeping methods 'just in case' — git history preserves them; remove now, restore if ever needed.
  • Not running dead code detection tools — PHPStan detects unused private methods automatically.
  • Unused abstract method implementations left after an interface changed.
  • Helper functions added during development that became unnecessary after refactoring.

Code Examples

✗ Vulnerable
class OrderService {
    public function processOrder(Order $o): void { /* used */ }

    private function formatOrderLegacy(Order $o): string {
        // Never called anywhere — dead code
        return $o->id . '-' . $o->total;
    }

    private function validateOrderV1(array $data): bool {
        // Replaced by validateOrder() — never called
        return isset($data['id']);
    }
}
✓ Fixed
// Remove unused private methods — git preserves the history:
class OrderService {
    public function processOrder(Order $o): void { /* used */ }
    // formatOrderLegacy() removed — was never called
    // validateOrderV1() removed — replaced by validateOrder()
}

Added 16 Mar 2026
Edited 22 Mar 2026
Views 45
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 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 2 pings T 2 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 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Scrapy 6 Ahrefs 4 ChatGPT 4 Perplexity 3 Bing 3 Google 2 Unknown AI 2 Claude 2 Meta AI 1 Sogou 1
crawler 32 crawler_json 6
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Install phpstan/phpstan-dead-code and run at level 6+ — it finds private/protected methods never called; public methods require more careful analysis as they may be called via reflection or from tests
📦 Applies To
PHP 7.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Private method never called within class; public method with zero callers across codebase; function defined never imported or called
Auto-detectable: ✓ Yes phpstan psalm php-dead-code
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Low Context: File Tests: Update
CWE-561


✓ schema.org compliant