Unused Function
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()
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
22
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 1
No pings yesterday
Amazonbot 9
Perplexity 3
Google 2
Ahrefs 2
Unknown AI 2
ChatGPT 2
Also referenced
How they use it
crawler 18
crawler_json 2
Related categories
⚡
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