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

Spread Operator & Variadic Args (PHP 5.6)

PHP PHP 5.6+ Beginner
debt(d5/e3/b3/t3)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5), because detection_hints lists rector and phpcs with code_pattern matching func_get_args() and call_user_func_array() — these are specialist static analysis / code-style tools, not default linters or compiler errors. The pattern is detectable automatically but requires these tools to be configured.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3), because quick_fix describes replacing func_get_args() with ...$params and call_user_func_array($fn, $args) with $fn(...$args) — a small, mechanical pattern replacement within one component. It's more than a single-line patch because multiple call sites may need updating, but it doesn't span the whole codebase architecturally.

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

Closest to 'localised tax' (b3), because the applies_to scope is broad (web, cli, queue-worker) but the common_mistakes are localised to function signatures and call sites. The burden is a persistent but contained tax — if old patterns like func_get_args() or call_user_func_array() are used, each affected function pays the cost but the rest of the codebase is largely unaffected.

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

Closest to 'minor surprise' (t3), because the misconception states that developers think ...args is only for variadic function definitions, missing that spread (...) also works in function calls to unpack any iterable. This is a one-directional edge-case misunderstanding, not a catastrophic or deeply contradictory trap — just a partial mental model that omits the call-site unpacking usage.

About DEBT scoring →

TL;DR

PHP 5.6 added variadic functions (...$args) and argument unpacking ($array...) — replacing func_get_args() and call_user_func_array() with clean syntax.

Explanation

PHP 5.6: variadic params: function sum(int ...$nums) { return array_sum($nums); }. Spread in calls: sum(...[1,2,3]). Before PHP 5.6: func_get_args() and call_user_func_array(). PHP 7.4 extended spread to arrays: [...$a, ...$b]. PHP 8.1 extended to string-keyed arrays. Variadic params must be last in parameter list. Type-hinting variadics: function join(string ...$parts). Named arguments (PHP 8.0) interact with variadics. The spread operator in function calls unpacks arrays/iterables into positional arguments.

Common Misconception

...args is only for variadic functions — spread (...) in function calls unpacks any iterable as arguments, useful for calling any function with a dynamic argument list.

Why It Matters

Variadic functions and spread operators eliminate common func_get_args() boilerplate and make dynamic function calls clean and type-safe.

Common Mistakes

  • Putting variadic param before other params — must be last.
  • Not type-hinting variadic params.
  • Still using call_user_func_array instead of fn(...$args).

Code Examples

✗ Vulnerable
// PHP 5.5 and older:
function sum() {
    return array_sum(func_get_args());
}
call_user_func_array('sum', $numbers);
✓ Fixed
// PHP 5.6+:
function sum(int ...$nums): int {
    return array_sum($nums);
}
sum(1, 2, 3);
sum(...[1, 2, 3]); // Spread from array

// Forwarding all args:
function wrapper(...$args) {
    return original(...$args);
}

Added 23 Mar 2026
Views 107
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 1 ping W 0 pings T 1 ping F 4 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
PetalBot 16 Amazonbot 10 ChatGPT 8 Ahrefs 7 Scrapy 7 Google 5 Bing 5 SEMrush 5 Unknown AI 4 Perplexity 3 Meta AI 2 Twitter/X 2 Applebot 2 Claude 1 Brave Search 1
crawler 73 crawler_json 3 your_contextpost 1 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
PHP php A server-side scripting language that generates web pages and APIs — the code runs on the server, and only its output (usually HTML or JSON) reaches the browser.

PHP is often the first server-side language people meet, and understanding its execution model — script starts fresh on every request, no memory between requests — explains most of how the web backend works: sessions, databases, and caching all exist to bridge that per-request amnesia.

💡 Start with PHP 8.x, declare(strict_types=1), and PDO — skip any tutorial that mentions mysql_query().

Ask Codex about PHP →
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
Replace func_get_args() with ...$params. Replace call_user_func_array($fn, $args) with $fn(...$args). Add type hints to variadic parameters.
📦 Applies To
PHP 5.6+ web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
func_get_args\(|call_user_func_array\(
Auto-detectable: ✓ Yes rector phpcs
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Function


✓ schema.org compliant