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

ArgumentCountError — Wrong Arg Count

PHP PHP 7.1+ Beginner
debt(d5/e3/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The term's detection_hints.tools list PHPStan and Psalm — both are specialist static analysis tools, not default linters. ArgumentCountError itself is a runtime error thrown immediately at the call site, but catching the misuse statically requires running PHPStan/Psalm. This fits d5 exactly.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates adding default values to new parameters, using named arguments, or catching the error at call sites — all small, targeted changes. The common_mistakes (e.g. adding a required param without updating callers) could touch multiple call sites but is still a find-and-replace-style refactor within one concern, not a cross-cutting architectural change.

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

Closest to 'localised tax' (b3). The applies_to covers web, cli, and queue-worker contexts broadly, but ArgumentCountError is a function-signature contract issue that is localised to the changed function and its direct callers. It does not impose a persistent productivity tax across the whole codebase — it surfaces quickly and is fixed locally.

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

Closest to 'notable trap' (t5). The misconception field explicitly states the key gotcha: developers assume passing extra positional arguments always throws an error, but PHP silently ignores them unless variadic syntax is used. This is a documented, well-known gotcha that most PHP developers encounter — fitting t5 (a documented trap most devs eventually learn) rather than a more severe contradiction of cross-language behaviour.

About DEBT scoring →

TL;DR

PHP 7.1+ throws ArgumentCountError when too few arguments are passed to a function — too many arguments are silently ignored (unless using strict_types).

Explanation

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.

Common 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.

Code Examples

✗ Vulnerable
function createUser(string $name, string $email, string $role): User {
    // ...
}
createUser('Paul', 'paul@example.com');
// ArgumentCountError: Too few arguments (2), 3 required
✓ Fixed
// Add with a default value to avoid breaking callers:
function createUser(string $name, string $email, string $role = 'user'): User {
    // ...
}
// Or use named arguments (PHP 8):
createUser(name: 'Paul', email: 'paul@example.com', role: 'admin');

Added 22 Mar 2026
Views 34
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 2 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 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 6 Perplexity 4 Unknown AI 3 Ahrefs 3 Scrapy 3 Google 2 Claude 2 ChatGPT 1 Meta AI 1 Sogou 1 PetalBot 1
crawler 23 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ 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.
📦 Applies To
PHP 7.1+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
ArgumentCountError
Auto-detectable: ✓ Yes phpstan psalm
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✗ Manual fix Fix: Low Context: Function Tests: Update
CWE-252


✓ schema.org compliant