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

Named Arguments in Built-in PHP Functions

PHP PHP 8.0+ Intermediate
debt(d5/e3/b5/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5). PHPStan and Psalm from detection_hints.tools can detect parameter name mismatches and flag when named arguments reference non-existent parameters, but this requires static analysis tooling rather than default linting.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). Per quick_fix, the fix involves updating parameter names or removing named argument usage — typically a search-and-replace pattern within affected call sites. May touch multiple files but follows a consistent pattern.

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

Closest to 'persistent productivity tax' (b5). The term applies across web/cli/queue-worker contexts per applies_to. Once named arguments are adopted in a codebase, parameter names become part of the public API contract, requiring ongoing attention during refactoring and version upgrades — a persistent but not system-defining consideration.

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

Closest to 'notable trap' (t5). The misconception states developers assume 'named arguments work identically for all PHP built-in functions' when parameter names may differ between extensions and versions. This is a documented gotcha that developers eventually learn, but the inconsistency with variadic functions and cross-version parameter naming creates real surprise.

About DEBT scoring →

Also Known As

named args in built-ins PHP built-in named parameters

TL;DR

PHP 8.0 named arguments work with built-in functions — enabling readable calls to functions with many optional parameters like array_slice().

Explanation

Named arguments (PHP 8.0) apply to built-in functions as well as userland code. This is particularly valuable for functions with many positional parameters where intermediate defaults must be skipped: array_slice($array, offset: 2, preserve_keys: true) is far clearer than array_slice($array, 2, null, true). Common built-in targets: str_contains, implode, array_map, array_filter (with mode:), htmlspecialchars (flags:, encoding:), json_encode (flags:, depth:). Caution: built-in parameter names are part of PHP's public API from 8.0 onward but some names changed between versions — check the manual. Named arguments cannot be used with variadic functions that spread into ...$args.

Common Misconception

Named arguments work identically for all PHP built-in functions. Built-in function parameter names are part of the PHP specification from 8.0+ but may differ between extensions and versions — named arguments on internal functions should be used with caution when writing code that must run on multiple PHP versions.

Why It Matters

PHP 8's named arguments work with all built-in functions — they are especially valuable for functions with many optional parameters like array_slice, implode, or htmlspecialchars where positional order is easy to get wrong.

Common Mistakes

  • Not using named arguments for built-in functions with confusing parameter order — str_contains vs strpos argument order differs.
  • Renaming function parameters in your own API and forgetting it is a breaking change for named argument callers.
  • Using named arguments with variadic functions — they interact in non-obvious ways.
  • Not using named arguments for clarity in calls with boolean flags: htmlspecialchars($str, double_encode: false).

Code Examples

✗ Vulnerable
// Confusing positional arguments:
$result = array_slice($arr, 1, 5, true); // What is 'true'?
$encoded = htmlspecialchars($str, ENT_QUOTES | ENT_HTML5, 'UTF-8', false); // Last arg?

// Named — self-documenting:
$result = array_slice($arr, offset: 1, length: 5, preserve_keys: true);
$encoded = htmlspecialchars($str, double_encode: false);
✓ Fixed
// Skip intermediate positional arguments cleanly
$slice = array_slice($items, offset: 5, preserve_keys: true);
$encoded = json_encode($data, flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

Added 15 Mar 2026
Edited 13 Jun 2026
Views 41
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping T 1 ping 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 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 2 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 1 ping S 1 ping S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Amazonbot 10 Ahrefs 4 Scrapy 4 Perplexity 3 Bing 3 SEMrush 3 Unknown AI 2 Google 2 ChatGPT 2 PetalBot 2 Claude 1 Meta AI 1
crawler 33 crawler_json 4
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
When designing PHP 8+ APIs avoid renaming function parameters in minor versions — parameter names are part of your public API contract when named arguments are used
📦 Applies To
PHP 8.0+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
Library function parameter renamed in minor version breaking callers using named arguments
Auto-detectable: ✓ Yes phpstan psalm rector
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✓ Auto-fixable Fix: Low Context: Line

✓ schema.org compliant