Function & Method Naming Convention
debt(d3/e1/b3/t3)
Closest to 'default linter catches the common case' (d3). The term's detection_hints list phpcs, phpmd, and phpstan — phpcs with PSR-1/PSR-2 rulesets will flag snake_case methods and missing verb prefixes as a default check, catching the most common naming violations automatically without specialist configuration.
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is a direct rename — e.g. rename get_user_by_id() to getUserById() or active() to isActive(). Each fix is a single rename operation per function, with IDE refactor tools making it a trivial one-step correction.
Closest to 'localised tax' (b3). Naming conventions apply across web, cli, and queue-worker contexts, so poor naming persists wherever those functions are called, but the debt is readable rather than structural — it slows comprehension locally without reshaping architecture. Each badly-named method is a small recurring tax rather than a gravitational force.
Closest to 'minor surprise' (t3). The misconception is that short names save typing (getUsrEmail vs getUserEmailAddress), which is a common but mild misunderstanding rather than a catastrophic gotcha. The snake_case vs camelCase confusion is also a one-time surprise for developers coming from Python/Ruby, but it's well-documented and quickly corrected.
Also Known As
TL;DR
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
Why It Matters
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
// 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
}
// 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 { }
}