{
    "slug": "php_argument_count_error",
    "term": "ArgumentCountError — Wrong Arg Count",
    "category": "php",
    "difficulty": "beginner",
    "short": "PHP 7.1+ throws ArgumentCountError when too few arguments are passed to a function — too many arguments are silently ignored (unless using strict_types).",
    "long": "ArgumentCountError extends TypeError extends Error. It's thrown when a function requiring N parameters receives fewer. Too many arguments is only an error in strict mode or with variadic functions. Common scenarios: refactoring a function to require more parameters breaks all callers, calling a method with wrong interface signature. In PHP 8, named arguments allow skipping positional requirements but still enforce parameter count. Check with func_num_args() in legacy variadic code.",
    "aliases": [],
    "tags": [
        "php",
        "errors",
        "functions",
        "arguments"
    ],
    "misconception": "Passing extra arguments always throws an error — PHP silently ignores extra positional arguments unless the function uses ... variadic syntax.",
    "why_it_matters": "ArgumentCountError surfaces interface contract violations immediately at the call site rather than creating undefined behaviour inside the function.",
    "common_mistakes": [
        "Adding a required parameter to an existing function without updating all callers.",
        "Not using default values for new optional parameters.",
        "Calling parent::__construct() with wrong argument count in subclasses."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "php_exception_hierarchy",
        "php_type_error",
        "named_arguments",
        "strict_types"
    ],
    "prerequisites": [
        "php_exception_hierarchy"
    ],
    "refs": [
        "https://www.php.net/manual/en/class.argumentcounterror.php"
    ],
    "bad_code": "function createUser(string $name, string $email, string $role): User {\n    // ...\n}\ncreateUser('Paul', 'paul@example.com');\n// ArgumentCountError: Too few arguments (2), 3 required",
    "good_code": "// Add with a default value to avoid breaking callers:\nfunction createUser(string $name, string $email, string $role = 'user'): User {\n    // ...\n}\n// Or use named arguments (PHP 8):\ncreateUser(name: 'Paul', email: 'paul@example.com', role: 'admin');",
    "quick_fix": "Add default values to new parameters to avoid breaking callers. Use PHP 8 named arguments for clarity. Catch \\ArgumentCountError or \\TypeError when calling dynamic callables.",
    "severity": "high",
    "effort": "low",
    "created": "2026-03-22",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/php_argument_count_error",
        "html_url": "https://codeclaritylab.com/glossary/php_argument_count_error",
        "json_url": "https://codeclaritylab.com/glossary/php_argument_count_error.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": "[ArgumentCountError — Wrong Arg Count](https://codeclaritylab.com/glossary/php_argument_count_error) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/php_argument_count_error"
            }
        }
    }
}