PHP 8.6 Partial Application: When Does the Argument Run?

PHP 8.6 partial function application can change when a supplied argument expression runs. A provided value is evaluated when the closure is created. By contrast, a helper inside an arrow function’s body runs when that callback is invoked. Decide whether the value should stay fixed before replacing one form with the other.

We ran a harmless local PHP 8.6.0 fixture to make that difference visible. After three callback calls, the partial form had evaluated its prefix helper once, while the arrow form had evaluated it three times. A constant-prefix control returned equal strings. These counts describe evaluation timing, not speed or application-wide compatibility.

PHP 8.6 partial function application: what changed

The 19 November PHP 8.6 release introduces the syntax. A call with supplied arguments and placeholders creates a closure for the remaining arguments. The feature can make a callback concise, but replacing a wrapper is still a behavior change to review rather than a formatting exercise.

The partial-application manual distinguishes a required single-argument placeholder from the remaining-arguments placeholder. It also specifies that supplied expressions are evaluated at creation. Those rules are the source-backed expectations for our fixture; the recorded run below is separate evidence.

A small helper that reveals evaluation timing

Our prefixValue helper increments a local counter and returns P followed by that count and a colon. The label function joins a prefix to its input string. We use invented inputs a, b and c. There are no files, accounts, network calls or real user records in this PHP fixture.

function prefixValue(): string {
    global $calls;
    $calls++;
    return "P" . $calls . ":";
}
function label(string $value, string $prefix = "K:"): string {
    return $prefix . $value;
}

$partial = label(?, prefixValue());
$arrow = fn(string $value): string => label($value, prefixValue());

The complete downloadable runner resets the counter between the two branches. It records the count immediately after creation and after every call. That reset matters: without it, the second branch could inherit the first branch’s counter value and make the comparison harder to interpret.

Observed cumulative helper counts are1,1,1,1 for partial application and0,1,2,3 for the arrow body at creation and after three calls
The helper runs once before the partial callback is invoked. The arrow branch begins at zero and increases on each call. The vertical scale counts evaluations, not milliseconds.
StagePartial helper callsArrow helper calls
After closure creation10
After first callback11
After second callback12
After third callback13
Actual local PHP 8.6.0 results, 23 November 2026. Each branch starts with a reset counter.

The returned strings explain why the count matters

The partial branch returned P1:a, P1:b and P1:c. It reused the prefix created when the closure was built. The arrow branch returned P1:a, P2:b and P3:c. Its helper stayed inside the body, so later calls received a different prefix. Equal first-call output therefore did not establish equal behavior.

InputPartial outputArrow outputConstant control: both
aP1:aP1:aK:a
bP1:bP2:bK:b
cP1:cP3:cK:c
Observed strings from the same fixture. The constant control supplied K: in both forms and produced equal output for all three inputs.

The constant control asks a narrower question. If the supplied prefix is already a fixed string, both callbacks can produce the same results for these inputs. That does not make every helper safe to move. A value that depends on changing state needs a separate decision about when it should be read.

The arrow-function reference also explains automatic by-value capture from the surrounding scope. A helper called inside the arrow body is different from a value computed outside it and captured. Keep the location of the computation visible in a code review; “arrow function” alone does not describe the timing.

Check extra callback arguments separately

Timing is not the only review field. Our fixture also calls a one-argument partial closure with an extra prefix. Without the remaining-arguments placeholder, the extra argument is ignored and the result is K:a. With that placeholder, it reaches label and the result is X:a. The runner records both strings.

$noForward = label(?);
$forward = label(?, ...);

$noForward("a", "X:"); // observed K:a
$forward("a", "X:");   // observed X:a

A callback producer can supply more arguments than the main input you had in mind. Write down the expected argument list before refactoring. Check the called function’s optional parameters too. A harmless-looking extra key or index should not accidentally become another function argument.

Choose fixed binding or per-call freshness

Two-column decision compares fixed creation-time values with values refreshed by a helper on each callback call; additional arguments need a separate check
Choose the form that preserves the intended value lifetime. Test returned strings and evaluation points, then review extra-argument forwarding independently.

Keep creation-time binding when the intended contract is to reuse one chosen value for the callback’s lifetime. Keep the helper in the body when each invocation should obtain a fresh value. If the requirement is unclear, ask what a second and third call should return before changing the syntax.

Our blank worksheet separates predictions from observations. It includes the provided expression, freshness requirement, counter before and after calls, returned strings, extra arguments, interpreter version and refactor decision. An unresolved value-lifetime question is a useful result, not a reason to tick the refactor as passed.

Method, source pack and boundaries

We downloaded the official PHP 8.6.0 source, checked its published SHA-256 and built a temporary CLI-only interpreter for this exercise. The command used that interpreter explicitly with configuration loading disabled. It did not replace a system PHP binary, change a web server or upgrade an existing application.

The source pack retains the PHP-only fixture, actual JSON output and source checksum. Keep its 8.6-only syntax in a separate test file and select a compatible interpreter before running it. A version check inside the same file is not a promise that an older parser can read the new syntax.

Tech Consulting Tailored to Your Coding Journey

Get expert guidance in coding with a personalized consultation. Receive unique, actionable insights delivered in 1-3 business days.

Get Started

We did not benchmark execution time, audit every callback API or test an entire application upgrade. For runtime identity and patch evidence, see our separate PHP verification guide. Dependency constraints belong in a project-level review, as our Composer guide explains.

Suggested citation: Learn Coding USA, “PHP 8.6 Partial Application: When Does the Argument Run?”, 23 November 2026. Describe the numbers as helper-evaluation counts from a synthetic local fixture, not a performance improvement.