Blog
November 19, 2026
PHP 8.6 has officially arrived, and it introduces several new features. One of them is Partial Function Application (PFA), which targets a familiar annoyance. When you want to reuse a function with some arguments fixed in advance, you typically wrap the call in a closure or arrow function. That works, but it adds boilerplate, especially when passing callbacks to functions like array_map() or using the pipe operator.
This post covers the history behind PFA, how it works, and how to use its placeholder syntax. Next, I look at how it pairs with the pipe operator, cover which limitations to watch for, and end by discussing what this new PHP 8.6 change means for the future of the language.
Back to topPartial Function Application in PHP: Development History
What does Partial Function Application solve within PHP development?
I'm going to illustrate with a (very) contrived example: a "normalizer" function that replaces space characters (' ') with dashes ('-'). Prior to PHP 8.6, we might write this as the following:
$normalizer = fn (string $subject): string => str_replace(' ', '-', $subject);Or, if we were concerned about scope binding, we might do a full closure:
$normalizer = function (string $subject): string {
return str_replace(' ', '-', $subject);
};The two are equivalent.
Why would you do this? A couple of reasons come to mind. First, to provide a consistent interface that describes the one variable argument that will be used, which leads to the second reason, to prevent copy-paste drift later, if the same calling pattern is used in multiple locations.
Both approaches represent a fair amount of boilerplate for a common scenario where the only thing changing is the third argument to str_replace().
Here's another good reason. As you likely know, the various array_*() functions for filtering, mapping, reducing, etc. have different argument orders. It's not uncommon for libraries to create their own cohesive variants that fix that order:
$map = array_map(...);
$reduce = fn (callable $callback, array $array, mixed $initial = null): mixed => array_reduce($array, $callback, $initial);
$filter = fn (callable $callback, array $array, int $mode = 0): array => array_filter($array, $callback, $mode);
$walk = function (callable $callback, array $array): array {
array_walk($array, $callback);
return $array;
};These definitions ensure that the first argument is always the callback, and the second argument the array to act on.
Partial Function Application aims to solve these sorts of problems: where a function already exists, but you want to "pre-fill" one or more arguments in order to simplify how the function is called and protect against potential change drift in the future, or when you want to change the order of arguments.
PHP Services
Planning a Migration to PHP 8.6?
Stay secure and supported while upgrading to the latest PHP version with full support from Zend Professional Services — including a complimentary code assessment of your application before your engagement begins.
How Partial Function Application Works in PHP 8.6
Partial Function Application builds on first class callables, which were introduced in PHP 8.1. First class callables provide a consistent, scope-friendly way of creating closures from existing functions and methods. Prior to their introduction, referencing these was messy, and often error-prone:
$function = 'strlen'; // string function name
$function = "$className::$methodName"; // Static class method
$function = [$className, $methodName]; // Class method; could be static or instance
$function = [$object, $methodName]; // Instance method
$function = $class // Invokable class instanceBecause how a callable was defined could affect whether or not calling it was successful (e.g., calling a class instance method when it was declared in such a way that it had to be a static method), developers and library maintainers often had to perform a bunch of heuristics to determine the validity of a callable before actually invoking it.
First class callables allow us to write something in a way that reflects its scope:
$function = strlen(...); // Map to a function
$function = SomeClass::someMethod(...);// Map to a static class method
$function = $object->someMethod(...); // Map to a class instance method
$function = $object->$methodString(...);// Map to a class instance method defined in another string!
$function = self::someMethod(...); // Map to an internal class instance method...and so on. In each case, the callable then accepts the exact same arguments as the function or method it refers to.
Which is where Partial Function Application finally comes into the picture.
Placeholders in the PHP Partial Function Application
PFA allows you to provide arguments when defining a first class callable, and to provide placeholders for one or more arguments in the signature that the resulting callable will then define as explicit arguments and pass on to the original function.
Placeholders can be a question mark (?) to indicate a single argument proxy, or an ellipsis (...) to indicate zero or more arguments at that position. The argument names, types, optionality (more on this below), default values, #[NoDiscard] and #[SensitiveParameter] attributes, and pass-by-ref flags are all retained, ensuring that the signature of the generated callable is compatible, and that you can use features such as named arguments when defining one.
However, once the feature landed in core, something quickly became clear: usage of ? must always indicate the argument is required to the generated callable, while arguments captured via ... can inherit optionality from the original signature. In fact, an addendum RFC was created to codify this behavior to prevent future issues.
How to Use Placeholders With PHP PFA
Now that we have covered what placeholders are, let's discuss what they actually look like in practice. To revisit the earlier examples:
// "Normalizer" example
$normalizer = str_replace(' ', '-', ?);
$slug = $normalizer('This is a string') // "This-is-a-string"
// Argument order changes
$map = array_map(...); // no change; we like this order
// For the following, array and callback swap order, and make extra arguments optional
$reduce = array_reduce(callback: ?, array: ?, ...);
$filter = array_filter(callback: ?, array: ?, callback: ?, ...);
$walk = array_walk(callback: ?, array: ?, ...);These are nice and clear: we know the order, we know what they represent, and we can be assured that the engine will take care of things like types and default values for us — and we didn't even have to reference them and potentially define them incorrectly in our code! This is a big win!
Back to topPFA and the Pipe Operator in PHP 8.6
While I hope the examples above give you enough to get you excited about Partial Function Application in PHP 8.6, the place these features really shine is with the pipe operator, introduced in PHP 8.5.
The pipe operator is a fantastic addition to the language, but when it dropped, there was a bit of a usability gap, particularly when it came to using the various array_*() functions. Because the pipe operator passes the result of one operation as the sole argument to the next argument, you had to create anonymous functions in order to do anything meaningful:
$emails = explode(';', $input)
|> (fn (array $emails) => array_filter($emails, is_string(...)))
|> (fn (array $emails) => array_map(trim(...), $emails))
|> (fn (array $emails) => array_map(strtolower(...),$emails))
|> (fn (array $emails) => array_filter(
$emails,
fn (string $email): bool => filter_var(
$email,
FILTER_VALIDATE_EMAIL | FILTER_FLAG_EMAIL_UNICODE,
null
) !==null
));With PFA in PHP 8.6, this becomes far easier both to create, as well as to read and understand:
$emails = explode(';', $input)
|> array_filter(?, is_string(...))
|> array_map(trim(...), ?)
|> array_map(strtolower(...), ?)
|> array_filter(?, ! filter_var(?, FILTER_VALIDATE_EMAIL| FILTER_FLAG_EMAIL_UNICODE, null));The power of this lies in the fact that you can see the exact function being called, understand what argument it will take, and the specific callback it will invoke. You don't have to dig through prior declarations (developers often define the callables ahead of such pipelines to make the pipeline more readable), look through additional code, or perform mental gymnastics to understand what it's trying to accomplish.
As a bonus, PFAs make delayed execution of a function possible. The ... placeholder can capture zero or more arguments, which means that you can place it at the end of an argument list in order to return the function as a closure instead of invoking it:
// Creates a closure without executing the request
$fetch = curl_exec($ch, ...);
// Later, we execute it, but only if a condition is met:
if ($user->isAllowed('fetch')) {
$fetch();
}Parameter-less delayed functions such as this are called "thunks".
There's a lot more you can do with PFA, and if you dive into Partial Function Application's RFC, you'll get a full picture. But the above sampling is representative of what I expect to be common usage of the feature.
Back to topLimitations to Watch With PHP Partial Function Application
For as concise and well scoped as the syntax is for PFA, there are still a few things to watch out for.
Evaluation Order
When it comes to arrow functions vs. PFA, there's one subtle difference that, while mostly obvious, can catch folks up: argument expressions are evaluated when you create a PFA. This is most easily illustrated with a function that has a side effect.
function example(string $message): string {
echo __FUNCTION__, "\n";
return $message;
}
// Arrow function
$arrow = fn($target) => printf('%s: %s', $target, example('This is the message'));
echo "Starting...\n";
$arrow('php');
/* Result:
Starting...
example
php: This is the message
*/
// PFA
$partial = printf('%s: %s', ?, example('This is the message'));
echo "Starting...\n"
$partial('php');
/* Result:
example
Starting...
php: This is the message
*/When you think about it, it's obvious: with the PFA, we're executing an expression as we define the PFA, which is why example is emitted first. In the case of the arrow function, it's part of the body of the closure, so it does not execute until the closure is called.
If you need to delay the side effects, you'll want to stick to arrow functions or closures.
Incompatible Functions
A number of PHP internal functions operate on the specific context in which they operate, and cannot be used with PFA as the whole point of PFA is to create a new context. These include, but aren't limited to:
compact()extract()func_get_arg()func_get_args()get_defined_vars()
Constructors and Other Magic Methods
__construct(), __call(), __get(), etc. — any of the class methods that begin with a double underscore (__) are considered special by the engine, as they generally have something to do with the object lifecycle. Some of these are fine to use with PFA: __invoke(), __call(), and __callStatic() operate in specific contexts and receive arguments as normal, so PFA works fine with them.
Others like __get() and __set() are never actually called as methods, but rather as part of property access, and cannot. Still others, like __construct(), have so many edge cases that the PHP internals team determined that supporting them for the few valid use cases didn't make sense. For that particular case, the authors of the RFC direct users to lazy objects, which were introduced in PHP 8.4.
Partial Function Application and the Future of PHP
Some will point to PFA as a step toward functional programming. It's not entirely wrong, but functional programming focuses on function purity — the idea that given the same input, a function will always return the same output, without side effects — and the majority of the examples I've shown here actually inject some state into the created closures, or produce side effects (such as seen with echo or printf statements).
Where I see PFA becoming a useful tool for PHP developers is the ability to reuse and repurpose existing functionality in the form of class methods and functions — redefining signatures to match business context, or providing extension points to hook into business workflows that can leverage existing functions and methods where certain values are already known.
Will the combination of PFA and the pipe operator negate the need for things like collections? Probably not, because one thing collections APIs provide is type safety and runtime optimization — something PHP's native arrays cannot do yet, until we have generics.
Back to topFinal Thoughts
PFA in PHP 8.6 gives developers a cleaner way to fix some arguments now and supply the rest later, with far less closure boilerplate. Paired with the pipe operator, it makes data transformations easier to read and compose. The limitations are manageable once you know about them, so test your existing code paths before relying on PFA in production.
As you plan your move to PHP 8.6, treat PFA as one piece of a larger upgrade. Review your codebase for compatibility issues, start experimenting with the syntax in low-risk areas, and build a timeline that fits your team's capacity. And remember, Zend is here to help if you run into any problems. If you decide you'd like expert assistance as you upgrade to PHP 8.6, we can support you from assessment through rollout.
PHP Services
Comprehensive Support for PHP Version Upgrades
Zend makes mission-critical PHP possible through our full suite of PHP services. Take advantage of long term support for EOL PHP versions, unlock 24/7/365 support from a global team of experts, and stay up to date on the latest security and performance enhancements PHP has to offer.
Additional Resources
- Guide - PHP Version and Release History
- On-Demand Webinar - The AI Vulnerability Explosion: How to Prioritize and Patch OSS
- Case Study - How a Global Healthcare Provider Modernized Critical PHP Applications
- Blog - How to Migrate to a New PHP Framework
- Blog - Updating PHP for More Secure Web Apps
- Blog - Enterprise Application Modernization: Hidden Costs to Watch