Skip to content

How to Use Partial Function Application in PHP 8.6

PHP 8.6 adds Partial Function Application with ? and ... placeholders. Learn how to create reusable closures, defer calls, combine PFA with pipes, and avoid its traps.

How to Use Partial Function Application in PHP 8.6

On this page

PHP 8.6.0 RC2 arrived on September 24, 2026, making Partial Function Application one of the new language features developers can now test before the stable release. Instead of writing a small closure whenever you want to fix some arguments of an existing function, PHP 8.6 lets you leave those arguments open with ? or .... This tutorial shows how the syntax works, when it is useful, and where it can produce surprising results.

What Partial Function Application actually does

Partial Function Application, usually shortened to PFA, means supplying some arguments to a function now while leaving the remaining arguments for later. The result is a Closure, which is PHP's object representing an executable anonymous function. The important distinction is that the original function does not run when a partial call is created.

For example, suppose you have a function that calculates a final price using an amount and a tax rate. Before PHP 8.6, fixing the tax rate normally meant writing an arrow function that accepted the amount and called the original function. PFA lets you describe the same relationship directly in the function call. The syntax therefore removes the repeated parameter and function-call boilerplate rather than introducing another callback abstraction.

Set one missing argument with the question-mark placeholder

The simplest PFA syntax uses ? for exactly one argument that will be supplied later. Consider a function with three parameters:

The expression containing the placeholders does not return a formatted string immediately. Instead, $doctorName becomes a closure waiting for the two missing arguments. Calling it with 'Jane' and 'Smith' supplies those values to the original function and produces Dr. Jane Smith.

Each ? represents one required argument on the resulting closure. Their order follows the positions of the placeholders in the original call, so the first question mark becomes the first missing argument and the second becomes the second. This makes the syntax easy to predict, but it also means that a function with many parameters can become difficult to read if placeholders are scattered across the call.

Use ellipsis when the remaining arguments should stay open

The second placeholder is ..., which means that the remaining arguments should be supplied later. It is useful when you want to lock in a group of leading arguments without writing out every remaining parameter. For example:

 42]);

Here the channel and logging level are fixed when $infoLog is created. The message and optional context remain available when the closure is called. Unlike ?, which represents exactly one missing argument, ... can cover zero or more arguments and preserves the optionality of parameters it brings into the generated closure.

You can also combine the two forms. A call such as logMessage('application', ?, ...) fixes the first argument, leaves the level open, and then leaves all later arguments available. The resulting closure therefore expects the missing level followed by the remaining arguments in the function's normal signature.

Replace simple callback closures with partial application

The practical value of PFA becomes clearer when a function is being used as a callback. Before PHP 8.6, you might write an arrow function solely to insert one fixed argument into an existing function. PFA can express that same callback without repeating the original parameter declaration.

 addPrefix('[WARNING] ', $value);

$addNotice = addPrefix('[NOTICE] ', ?);

echo $addNotice('Disk space is low');

The two approaches perform the same basic job, but the partial version directly exposes which argument has been fixed and which one remains variable. This is especially useful for small callback adapters used with functions such as array_map(), where the callback already exists and only a few of its arguments need to be predetermined. The PHP RFC also specifies that the generated closure carries information derived from the original callable, including parameter and return-type information.

Use PFA when a function needs to run later

PFA is not limited to callbacks. The ... placeholder can create a callable whose arguments have all been supplied but whose underlying function has not yet executed. This is useful when you want to prepare a task now and decide later whether to run it.

The important detail is the timing. Creating $calculateWithTax does not calculate the total; the original function is called when the resulting closure is invoked. This can be useful for deferred callbacks, configuration, or code paths where a prepared operation should only execute if a later condition is met.

There is a subtle difference from wrapping the call in an arrow function, however. Arguments supplied during partial application are evaluated when the partial call is created. If one of those fixed arguments comes from another function, that function runs immediately rather than waiting for the resulting closure to be invoked. This is one of the details worth testing before replacing an existing closure with PFA.

Combine PHP 8.6 PFA with the PHP 8.5 pipe operator

PHP 8.5 introduced the pipe operator, written as |>, which passes the value on the left into the callable on the right. The limitation is that the piped value is supplied as the first argument. That is awkward for functions such as array_map(), where the array being processed is not the first parameter.

PFA gives the pipe a way to fill a different argument position. For example:

 array_map(trim(...), ?)
    |> array_values(?);

In the first step, ? marks the array argument while trim(...) supplies a first-class callable for the callback. The pipe therefore produces a callable that receives the array in the correct position rather than forcing you to write another wrapper function. The second step uses the same idea because array_values() expects the array as its first argument.

This combination is one of the more interesting reasons to learn PFA now. PHP 8.5 made left-to-right transformation chains possible, while PHP 8.6 supplies a concise way to adapt functions whose useful input is not already in the first parameter position. You do not need to use both features together, but they solve related problems.

Understand what the generated closure contains

A partial application produces a closure rather than immediately producing the result of the original function. PHP derives the remaining closure parameters from the underlying callable, which means the generated callable can retain useful type information. This is different from simply storing an arbitrary callback in a variable because the partial call describes which arguments have already been supplied.

The distinction is also useful when comparing PFA with first-class callable syntax introduced in PHP 8.1. A first-class callable such as strtoupper(...) turns the complete callable into a closure while leaving all of its arguments open. Partial application goes one step further by allowing specific arguments to be fixed at the point where the callable is created.

Watch the optional-parameter rule when using question marks

PHP 8.6 also changed an easy-to-miss detail around optional parameters. A parameter represented by ? becomes a required parameter on the generated closure, even if the original function declared a default value for that parameter. Parameters brought in through ... retain their original optional behavior.

Here the fixed prefix is already supplied, so the generated closure only needs the text. If instead you use a question mark for an originally optional parameter, you should treat that placeholder as something the caller must provide. The rule makes generated signatures more predictable, but it is another reason to inspect the original function signature before introducing placeholders.

Avoid using PFA where an ordinary closure is clearer

New syntax is not automatically better syntax. A partial call is most useful when you are genuinely adapting an existing callable by fixing some of its arguments. If the operation contains additional business logic, multiple conditions, error handling or transformations, an ordinary named function or arrow function can communicate the intent more clearly.

There are also hard boundaries in the current implementation. Partial application does not support new expressions, so code such as new User(?, 'customer') is not a valid way to create a partially applied constructor. A static factory method or an ordinary closure can handle that case instead. The PHP 8.6 RFC also documents restrictions around placeholder ordering and special callable behavior, so complex signatures deserve a quick test rather than an assumption that every normal function call can be converted directly.

Test PFA on PHP 8.6 before using it in production

PHP 8.6.0 RC2 is a release candidate, not a production release. The PHP project published it on September 24, 2026, and describes it as a version for testing; the planned general availability date is November 19, 2026. RC2 was also unusual because a packaging mistake caused the release candidate numbered RC1 to be replaced by RC2, making RC2 the first release candidate developers are testing.

For experimentation, keep a small PHP 8.6 test project separate from a production application and try PFA against the callbacks you actually use. Start with one fixed argument, then test multiple ? placeholders, trailing ..., optional parameters and pipe expressions. Pay particular attention to when fixed argument expressions execute, because that timing difference can matter when the argument reads changing state or performs work.

Do not deploy PHP 8.6.0 RC2 to production solely to try PFA. The PHP project explicitly identifies RC2 as a testing release, and the stable PHP 8.6 release is scheduled for November 19, 2026.

Once PHP 8.6 becomes stable, the feature is most likely to earn its place in codebases where the same callable is repeatedly reused with a few arguments fixed. That includes callback-heavy data processing, reusable formatting functions and pipelines built around PHP's pipe operator. The useful habit is to treat ? and ... as tools for removing a specific piece of callback plumbing, not as replacements for every small closure in an application.

Muhammad Saleem profile photo

Written by

Muhammad Saleem

I’m Muhammad Saleem, a web developer and the owner of TechWare House, a software house focused on practical web and software solutions. With over 14 years of experience, I’ve built and managed hundreds of websites and custom , PHP/MySQL, Python, Django applications. I share hands-on insights about web development, software, technology, and digital solutions on WizTechnoz.com

148 posts published

All posts by this author

Copy this post

0 Comments

No comments yet. Be the first to share your thoughts.

Join the conversation

Log in or create a free account to leave a comment. You can edit or delete your own comments any time.