Pipe Operator

Status: The Pipe Operator is a new feature being introduced in PHP 8.5 (November 20, 2025).

The Pipe Operator |> is a language feature that enables functional composition by chaining operations in a left-to-right syntax.

#How it works

Rather than nesting function calls or creating intermediate variables, the pipe operator passes the result of one expression directly as the first parameter to the next callable.

Ring Donut Base

Traditional approach:

With pipe operator:

Let's compare code in the context of making donuts. Go ahead - add a few toppings!

Both these examples produce identical results, but the pipe syntax transforms how we read and follow the flow of the code.

The traditional approach shows how calls are nested and therefore forces you to parse the code from the inside out. You must first find bakeDonut(), then move outward for each topping.

The pipe operator follows a natural reading flow: start with the input, then follow each step sequentially. This eliminates the cognitive overhead of matching parentheses and makes it trivial to add, remove, or reorder the steps.

Practical Example

User processing pipeline:

$adminCount = getUsers()
|> fn($users) => array_filter($users, isAdmin(...))
|> count(...);

This pipeline:

  1. Retrieves all users from the system
  2. Filters the collection to admin users only
  3. Returns the total count of administrators

#Syntax

  • Each callable must accept exactly one required parameter
  • Data flows left-to-right through the pipeline: A |> B |> C
  • Supports any valid PHP callable (functions, methods, closures, first-class callables)

First-Class Callable Notation

The pipe operator works well with PHP 8.1's first-class callable syntax ...:

// First-class callable syntax
$result = "hello world" |> strtoupper(...) |> trim(...);
// Works with any callable type
$data = getUsers()
|> fn($users) => array_filter($users, isAdmin(...)) // Function reference
|> array_values(...) // Built-in function
|> Processor::processUsers(...) // Static method
|> $processor->transform(...); // Instance method

The ... syntax creates a callable reference without invoking the function, making it useful for pipe chains.

Benefits

  • Enhanced readability: Eliminates deeply nested function calls
  • Improved maintainability: Linear data flow is easier to debug and modify
  • Reduced complexity: Removes the need for temporary variables
  • Performance optimization: Compiler-level optimizations

Partial Function Application

Work has begun on a complementary feature called Partial Function Application targeting PHP 8.6. This enhancement would introduce ? as a placeholder to the syntax and provide better control over parameter placement in multi-argument functions.

Current limitation with pipe operator:

// Requires a closure for multi-parameter functions
$result = $data |> fn($x) => str_replace(' ', '-', $x);

Proposed syntax:

// Clean placeholder syntax with partial function application
$result = $data |> str_replace(' ', '-', ?);

The ? placeholder creates a partially applied function where the piped value fills the marked position. This would remove the need to wrap steps in a closure for multi-parameter functions, making pipe chains more readable and concise.

Also being considered:

  • Multiple placeholders
  • Named argument support
  • Variadic placeholders for spread operations

While this feature is still being discussed, and not yet confirmed for any specific release, it does demonstrate the continued effort being made to improve PHP's programming capabilities.

#Further Reading


Did you know this article uses Event Sourcing to store your donut creation? The events are used to create the preview and code examples! Interested in Event Sourcing? Be sure to subscribe to my newsletter!