Function & Method Naming Convention
Also Known As
camelCase method
method naming
function name
TL;DR
PHP functions and methods use camelCase per PSR-1 — lowercase first word, each subsequent word capitalised, verb-noun pairs for actions.
Explanation
PSR-1 mandates camelCase for method names. Effective method names follow verb-noun patterns: getUser(), saveOrder(), isActive(), hasPermission(). Boolean methods use is/has/can/should prefix. Getters use get prefix; setters use set. Factory methods use make/create/build. PHPUnit test methods use test prefix (testUserCanLogin) or @test annotation. Avoid abbreviations (getUsrNm → getUserName) and avoid generic names (process, handle, run — what does it do?).
Common Misconception
✗ Short method names are better because they save typing — method names are read far more often than they are typed; getUserEmailAddress() is always clearer than getUsrEmail().
Why It Matters
Well-named methods make code readable without needing comments — findActiveUsersByRole() explains exactly what happens; process() explains nothing.
Common Mistakes
- snake_case methods: get_user_by_id() — PHP is camelCase for methods.
- No verb prefix: user() instead of getUser() or findUser().
- Boolean methods without is/has/can: active() instead of isActive().
- Overly abbreviated names: getUsrNm() — spell it out: getUserName().
Code Examples
✗ Vulnerable
// Wrong conventions:
class UserService {
public function get_user(int $id) { } // snake_case
public function User(int $id) { } // Uppercase, no verb
public function active(): bool { } // No is/has/can prefix
public function DoSomething() { } // Uppercase verb, vague
public function proc(array $d) { } // Abbreviations
}
✓ Fixed
// PSR-1 camelCase with clear verb-noun:
class UserService {
public function findById(int $id): ?User { }
public function isActive(User $user): bool { }
public function canDelete(User $user, Resource $r): bool { }
public function createFromRequest(Request $r): User { }
public function updateEmailAddress(User $u, string $email): void { }
}
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
23
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Perplexity 6
Ahrefs 2
Google 2
Unknown AI 2
How they use it
crawler 17
crawler_json 1
Related categories
⚡
DEV INTEL
Tools & Severity
🟢 Low
⚙ Fix effort: Low
⚡ Quick Fix
Name functions with a verb + noun: calculateTax(), sendWelcomeEmail(), validateUserInput() — and be consistent with verb tense: isValid() for boolean checks, getUser() for retrieval, createOrder() for creation
📦 Applies To
any
web
cli
queue-worker
🔗 Prerequisites
🔍 Detection Hints
Functions named with nouns: user(), order(); boolean functions without is/has/can prefix; inconsistent tense: get vs fetch vs load
Auto-detectable:
✓ Yes
phpcs
phpmd
phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Medium
False Positives: Medium
✓ Auto-fixable
Fix: Low
Context: File