{
    "slug": "function_naming_convention",
    "term": "Function & Method Naming Convention",
    "category": "style",
    "difficulty": "beginner",
    "short": "PHP functions and methods use camelCase per PSR-1 — lowercase first word, each subsequent word capitalised, verb-noun pairs for actions.",
    "long": "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?).",
    "aliases": [
        "camelCase method",
        "method naming",
        "function name"
    ],
    "tags": [
        "style",
        "php",
        "psr-1",
        "naming"
    ],
    "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()."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "naming_conventions",
        "psr_1",
        "class_naming_convention"
    ],
    "prerequisites": [
        "clean_code_naming",
        "psr_12",
        "single_responsibility"
    ],
    "refs": [
        "https://www.php-fig.org/psr/psr-1/#42-properties"
    ],
    "bad_code": "// Wrong conventions:\nclass UserService {\n    public function get_user(int $id) { }   // snake_case\n    public function User(int $id) { }       // Uppercase, no verb\n    public function active(): bool { }      // No is/has/can prefix\n    public function DoSomething() { }       // Uppercase verb, vague\n    public function proc(array $d) { }     // Abbreviations\n}",
    "good_code": "// PSR-1 camelCase with clear verb-noun:\nclass UserService {\n    public function findById(int $id): ?User { }\n    public function isActive(User $user): bool { }\n    public function canDelete(User $user, Resource $r): bool { }\n    public function createFromRequest(Request $r): User { }\n    public function updateEmailAddress(User $u, string $email): void { }\n}",
    "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",
    "severity": "low",
    "effort": "low",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/function_naming_convention",
        "html_url": "https://codeclaritylab.com/glossary/function_naming_convention",
        "json_url": "https://codeclaritylab.com/glossary/function_naming_convention.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Function & Method Naming Convention](https://codeclaritylab.com/glossary/function_naming_convention) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/function_naming_convention"
            }
        }
    }
}