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

Named Arguments (PHP 8.0)

PHP PHP 8.0+ Beginner
debt(d5/e1/b1/t3)
d5 Detectability Operational debt — how invisible misuse is to your safety net

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.

e1 Effort Remediation debt — work required to fix once spotted

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.

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

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.

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

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.

About DEBT scoring →

TL;DR

PHP 8.0 named arguments let you pass values by parameter name — skipping optional params, self-documenting calls, and enabling out-of-order argument passing.

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

Named arguments change how functions are implemented — they only affect call sites. The function signature is unchanged.

Why It Matters

Named arguments eliminate the need to remember parameter order for functions with many optional params — making complex built-in function calls self-documenting.

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

✗ Vulnerable
array_slice($array, 1, 3, true); // What is true?
setcookie('session', $val, 0, '', '', true, true); // What are the booleans?
✓ Fixed
array_slice($array, offset: 1, length: 3, preserve_keys: true);

setcookie(
    name: 'session',
    value: $val,
    secure: true,
    httponly: true
);

Added 23 Mar 2026
Edited 13 Jun 2026
Views 43
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 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 7 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
PetalBot 1
Amazonbot 9 ChatGPT 7 Google 4 Unknown AI 3 Ahrefs 3 Scrapy 3 Perplexity 2 Claude 1 Meta AI 1 PetalBot 1
crawler 30 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Add named arguments to complex built-in calls (array_slice, setcookie, preg_replace). Always use named args in attribute constructors with multiple params.
📦 Applies To
PHP 8.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
setcookie\(|array_slice\(
Auto-detectable: ✗ No rector
🤖 AI Agent
Confidence: Low False Positives: High ✓ Auto-fixable Fix: Low Context: Line

✓ schema.org compliant