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

Class Naming Convention

style PHP 5.0+ Beginner

Also Known As

PascalCase class UpperCamelCase class name

TL;DR

PHP classes must use PascalCase (UpperCamelCase) per PSR-1 — each word capitalised, no underscores, descriptive nouns or noun phrases.

Explanation

PSR-1 mandates PascalCase for class names. Good class names are: specific (UserRepository not DataManager), nouns or noun phrases (Order, EmailService, InvoicePdfGenerator), and consistent with domain language. Avoid generic names (Manager, Handler, Helper, Processor) — they signal low cohesion. Abstract classes and interfaces have no required prefix/suffix in PSR standards but many teams use Interface suffix or I prefix for interfaces, Abstract prefix for abstract classes.

Common Misconception

Suffixing every class with its type (UserClass, OrderModel, PaymentInterface) makes code clearer — the namespace provides context; User and Order are clearer than UserClass and OrderModel.

Why It Matters

Consistent naming conventions allow developers to infer class purpose and type from the name alone, reducing the cognitive load of navigating an unfamiliar codebase.

Common Mistakes

  • snake_case or camelCase class names: user_service, userService — must be UserService.
  • All-caps acronyms: HTMLParser — prefer HtmlParser (only first letter capped).
  • Generic names: DataManager, BaseHelper — be specific about what the class does.
  • Class name not matching filename — PSR-4 requires App\User to be in App/User.php.

Code Examples

✗ Vulnerable
// Wrong naming:
class user_repository { }    // snake_case — wrong
class userService { }        // camelCase — wrong
class PAYMENTGATEWAY { }     // ALL_CAPS — wrong
class data_manager { }       // Generic + snake_case
class HTMLrenderer { }       // Inconsistent acronym caps
✓ Fixed
// Correct PascalCase, specific names:
class UserRepository { }     // PascalCase, specific
class PaymentGateway { }     // PascalCase, domain term
class HtmlRenderer { }       // Acronym: only first letter capped
class InvoicePdfGenerator { } // Multi-word, clear purpose
class OrderNotFoundException extends RuntimeException { }

Added 16 Mar 2026
Edited 22 Mar 2026
Views 24
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 8 Perplexity 6 Unknown AI 2 Google 1 Ahrefs 1
crawler 18
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Use PascalCase nouns for classes: OrderProcessor not ProcessOrders; suffix with role when ambiguous: UserRepository, OrderFactory, PaymentService
📦 Applies To
PHP 5.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Class names with verb prefixes ProcessOrder; abbreviations UsrMgr; non-PascalCase; generic suffixes Manager Helper Util with 10+ unrelated methods
Auto-detectable: ✓ Yes phpcs phpstan phpmd
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Low ✓ Auto-fixable Fix: Low Context: File

✓ schema.org compliant