← 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/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list Rector and phpcs — both specialist/configurable tools rather than default linters. The common mistake of renaming a parameter without treating it as a breaking change (silently breaking named-argument callers) is also not caught by the compiler and requires code review or these specialist tools to detect.

e1 Effort Remediation debt — work required to fix once spotted

Closest to 'one-line patch or single-call swap' (e1). The quick_fix is literally a one-line replacement at the call site — swap positional arguments for named ones (or vice versa). No structural change needed.

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

Closest to 'localised tax' (b3). Named arguments impose a burden primarily at the parameter-naming level: renaming a function's parameters becomes a breaking change if callers use named args. This affects only the functions/components that adopt this style, not the entire codebase architecture, though it does create a mild persistent contract around parameter names.

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

Closest to 'notable trap' (t5). The misconception field states developers treat named arguments as 'just more verbose positional arguments,' missing that they allow skipping optional params and are order-independent. The documented gotcha — that renaming parameters is now a breaking change for callers using named args — is a well-known but frequently overlooked pitfall that most developers encounter eventually.

About DEBT scoring →

Also Known As

PHP named arguments named parameters PHP 8 named args

TL;DR

Pass arguments to a function by parameter name rather than position, improving readability and allowing optional parameters to be skipped.

Explanation

Named arguments (PHP 8.0+) allow calling functions with label: $value syntax, making long argument lists self-documenting and enabling skipping of optional parameters without passing null placeholders. For example, array_slice($array, offset: 2, preserve_keys: true) is clearer than array_slice($array, 2, null, true). They also work with built-in functions and constructors. Named arguments are positional-order-independent, but must come after positional arguments.

Common Misconception

Named arguments are just more verbose positional arguments. Named arguments allow skipping optional parameters, improve readability of calls with many arguments, and are order-independent — they also make code more resilient to function signature changes that add parameters in the middle.

Why It Matters

Named arguments (PHP 8.0+) let you pass arguments by parameter name in any order — they make calls with many optional parameters self-documenting and eliminate error-prone positional argument counting.

Common Mistakes

  • Using named arguments for all calls — they are most valuable when skipping optional parameters or for clarity.
  • Renaming function parameters without treating it as a breaking change — named argument callers break silently.
  • Not using named arguments with built-in functions that have confusing parameter order — e.g., array_slice($arr, offset: 2, length: 5).
  • Mixing positional and named arguments where the positional arguments come after named ones — PHP requires positional arguments first.

Code Examples

✗ Vulnerable
// Cryptic positional arguments:
$result = array_slice($users, 1, 5, true); // What does 'true' do here?

// Self-documenting with named arguments:
$result = array_slice($users, offset: 1, length: 5, preserve_keys: true);
✓ Fixed
// Before: cryptic positional arguments
$result = array_slice($array, 2, null, true);

// After: self-documenting with named args
$result = array_slice(array: $array, offset: 2, preserve_keys: true);

// Skip optional parameters you don't need
str_contains(haystack: $html, needle: '</body>');

// Named args in constructors — order doesn't matter
$req = new CreateUserRequest(
    email: 'alice@example.com',
    role:  'admin',
    name:  'Alice',
);

Tags


Added 15 Mar 2026
Edited 22 Mar 2026
Views 64
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 1 ping T 3 pings F 2 pings S 4 pings S 4 pings M 2 pings T 2 pings W 1 ping 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
Scrapy 14 Perplexity 10 Amazonbot 9 SEMrush 5 Ahrefs 4 ChatGPT 3 Google 3 Unknown AI 2 Claude 2 Bing 2 Majestic 1 Meta AI 1 PetalBot 1
crawler 54 crawler_json 3
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
Use named arguments for functions with many parameters to make call sites self-documenting: array_slice(array: $arr, offset: 2, length: 5)
📦 Applies To
PHP 8.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Function calls with many positional arguments where intent is unclear; null placeholders for optional params
Auto-detectable: ✓ Yes rector phpcs
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✓ Auto-fixable Fix: Low Context: Function


✓ schema.org compliant