Named Arguments (PHP 8.0)
debt(d5/e1/b1/t3)
Closest to 'specialist tool catches it' (d5). The detection_hints list Rector as the tool, and automated is marked 'no' — meaning misuse (e.g. mixing positional and named args incorrectly, or using named args unnecessarily for the first positional arg) isn't caught by a default linter but can be surfaced by Rector with specific rules. It won't cause a silent production failure (ruling out d7/d9), but it's not caught by a compiler or default linter either.
Closest to 'one-line patch or single-call swap' (e1). The quick_fix is explicitly about adding named arguments to individual call sites (array_slice, setcookie, etc.) — a local, one-line change per call site with no cross-cutting impact.
Closest to 'minimal commitment' (b1). Named arguments only affect call sites, not function signatures (confirmed by the misconception field). Each usage is isolated; there is no architectural weight, no shared state, and no persistent tax on future maintainers. The choice is purely local to the call site.
Closest to 'minor surprise — one edge case' (t3). The misconception states that devs may believe named arguments change function implementations, but they only affect call sites. Additionally, common mistakes include mixing positional and named args incorrectly. These are minor, single gotchas rather than a contradictory or catastrophic trap.
TL;DR
Explanation
named_arg: value syntax at call sites: array_slice($arr, offset: 1, length: 3). Benefits: skip optional params with defaults, document complex calls, reorder args. Works with built-in functions too: htmlspecialchars($str, ENT_QUOTES | ENT_SUBSTITUTE, encoding: 'UTF-8'). In attributes: #[Route(path: '/home', methods: ['GET'])]. Named args cannot be combined with positional args in PHP 8.0 (fixed in 8.1). Spreading named args: fn(...$named). Cannot use named args for constructors with property promotion before 8.1. Named args in array_slice removed need to pass all earlier args.
Common Misconception
Why It Matters
Common Mistakes
- Using named args for the first positional argument — only useful for optional params.
- Mixing positional and named args incorrectly (positional must come first).
- Not using named args in attributes where they dramatically improve readability.
Code Examples
array_slice($array, 1, 3, true); // What is true?
setcookie('session', $val, 0, '', '', true, true); // What are the booleans?
array_slice($array, offset: 1, length: 3, preserve_keys: true);
setcookie(
name: 'session',
value: $val,
secure: true,
httponly: true
);