ArgumentCountError — Wrong Arg Count
debt(d5/e3/b3/t5)
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.
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.
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.
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.
TL;DR
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
Why It Matters
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
function createUser(string $name, string $email, string $role): User {
// ...
}
createUser('Paul', 'paul@example.com');
// ArgumentCountError: Too few arguments (2), 3 required
// 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');