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

Unused Function

quality PHP 7.0+ Beginner

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 22
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings 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 1 ping W 0 pings T 2 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S
No pings yesterday
Amazonbot 9 Perplexity 3 Google 2 Ahrefs 2 Unknown AI 2 ChatGPT 2
crawler 18 crawler_json 2
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