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

Naming Conventions

style PHP 5.0+ Beginner
debt(d3/e1/b5/t3)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). The detection_hints list phpcs, phpstan, and phpmd — all standard PHP tooling that catches naming violations automatically. phpcs in particular enforces PSR-1/PSR-12 naming rules out of the box, making this a default-linter-level catch.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is a direct prescription: enforce phpcs with PSR-1/PSR-12 rules and rename symbols according to convention. Individual violations are single-symbol renames; a codebase-wide rollout is a mechanical find-and-replace that tooling can automate.

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

Closest to 'persistent productivity tax' (b5). Naming conventions apply across web, cli, and queue-worker contexts (all PHP contexts per applies_to), and inconsistency slows down every developer reading unfamiliar code. However, once a consistent standard is adopted and enforced by phpcs, the ongoing burden is moderate rather than gravitational — it doesn't shape architecture, just readability across many work streams.

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

Closest to 'minor surprise (one edge case)' (t3). The misconception field identifies the trap: developers believe internal consistency is sufficient, not realising PSR conventions are required for third-party tooling and framework integration. This is a real gotcha but not a deep contradiction — it's a 'good enough is not enough' surprise rather than a behavioural inversion.

About DEBT scoring →

Also Known As

PHP naming conventions PSR naming snake_case vs camelCase

TL;DR

Consistent naming rules for classes, methods, variables, and constants that make code self-documenting and predictable.

Explanation

PHP PSR-1 and PSR-12 conventions: class names in PascalCase (UserRepository), methods and properties in camelCase (getUserById), constants in UPPER_SNAKE_CASE (MAX_RETRIES), and variables in camelCase ($userId). Namespace names in PascalCase matching directory structure. Good names reveal intent: $elapsedTimeInDays is better than $d. Avoid abbreviations, type prefixes (Hungarian notation), and single-letter variables outside tight loops. Consistency within a codebase matters more than any single convention — pick one and enforce it with tools.

Common Misconception

Naming conventions are optional in a codebase as long as it is internally consistent. Consistency within a project is the minimum bar, but PSR conventions enable third-party developers, tools, and framework integrations to understand the code immediately without a style guide briefing.

Why It Matters

Consistent naming conventions let developers read unfamiliar code faster — conventions signal intent (constant vs variable, interface vs class) without requiring documentation.

Common Mistakes

  • Class names in snake_case instead of PascalCase — violates PSR and PHP community standard.
  • Constants in camelCase instead of UPPER_SNAKE_CASE — indistinguishable from variables at a glance.
  • Boolean variables without is/has/can prefix — $active could be a user object or a boolean.
  • Abbreviations that are not universally understood: $usrMgr, $cfg, $rsp — spell things out.

Code Examples

✗ Vulnerable
// PHP naming violations:
$UserName = 'Alice';         // PascalCase variable — looks like a class
function Get_User() {}       // Mixed conventions
const maxRetries = 3;        // camelCase constant — should be MAX_RETRIES
class user_repository {}     // snake_case class — should be UserRepository
$active = getUser();         // $active sounds boolean but holds an object
✓ Fixed
// PHP naming conventions (PSR-1 / community standard)
class OrderProcessor {}         // PascalCase

public function processOrder(): void {} // camelCase method

const MAX_RETRY_ATTEMPTS = 3;   // UPPER_SNAKE_CASE constant

$orderId = 42;                  // camelCase variable

// Boolean names should read as questions
public bool $isActive;
public bool $hasDiscount;
public bool $canRefund;

// Collections are plural
public array $orders;

// Avoid abbreviations that save 2 keystrokes but cost readability
// Bad: $usrCnt  Good: $userCount

Added 15 Mar 2026
Edited 22 Mar 2026
Views 28
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 2 pings W 2 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F
No pings yet today
No pings yesterday
Perplexity 8 Amazonbot 6 Ahrefs 4 Google 3 Unknown AI 2 ChatGPT 2 Majestic 1
crawler 23 crawler_json 3
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Follow PSR-1/PSR-12: PascalCase classes, camelCase methods and properties, SCREAMING_SNAKE_CASE constants — enforce with phpcs; the framework (Laravel/Symfony) conventions override for specific contexts like controllers
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
snake_case class names; camelCase file names not matching class; ALLCAPS method names; inconsistent naming within same codebase
Auto-detectable: ✓ Yes phpcs phpstan phpmd
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✓ Auto-fixable Fix: Low Context: File

✓ schema.org compliant