PHP 8.5 introduces the new pipe operator |>, and it immediately changes how many of us write everyday PHP. The idea is simple: you take a value on the left, send it through a series of callables on the right, and read the whole expression from left to right.
Instead of nesting function calls or juggling temporary variables, the pipe operator lets you describe a small data pipeline in one clear expression. Your code becomes easier to scan, easier to explain, and easier to change later.
What the pipe operator actually does
The pipe operator has one core job:
Take the result on the left and pass it as the first argument to the callable on the right.
In other words, this:
$result = $value
|> trim(...)
|> strtoupper(...);Means:
- Start with $value
- Call trim($value)
- Take that result and call strtoupper() with it
- The final result is stored in $result
The right side uses callables such as trim(…), which is PHP’s first-class callable syntax.
Why the pipe operator is helpful
Before PHP 8.5, you usually had to choose between:
- Nested calls, which are compact but hard to read inside out
- Temporary variables, which are clearer but add a lot of small assignments
The pipe operator gives you a third option that is often easier to follow:
- You read the code from top to bottom
- Each step does exactly one thing
- You can add, reorder, or comment out steps without reformatting a mess of nested calls
It does not let PHP do anything completely new. It is mostly about readability and expressing intent.
A quick, realistic example
Imagine you want to turn a title into a URL slug. With the pipe operator, you can describe that as a small pipeline:
$title = ' PHP 8.5 Pipe Operator Overview ';
$slug = $title
|> trim(...)
|> fn (string $value): string =>
preg_replace('/[^a-z0-9]+/i', '-', $value)
|> strtolower(...)
|> fn (string $value): string =>
trim($value, '-');Even without thinking too hard, you can see the flow:
- Trim whitespace
- Replace non-alphanumeric characters
- Lowercase the result
- Trim extra dashes
That is the sweet spot for the pipe operator: small, ordered transformations on a value.
The important rules and limitations
There are a few rules you need to know to avoid surprises.
$parts = 'a,b,c'
|> fn (string $value): array =>
explode(',', $value);- Single parameter callables The operator is defined to pass the piped value as the first argument. If a function needs extra required parameters, you normally wrap it in a small closure that adapts it:
- No by reference parameters Functions that require by reference parameters, such as array_pop, cannot be used directly in a pipe chain. There is no normal variable for PHP to pass by reference, so these are intentionally not supported.
- Avoid void in the middle of a chain The pipe operator expects each step to return a value. If a callable returns void, the result becomes null, and anything after that in the chain will receive null. In practice, keep void style functions at the end of a pipeline, or call them outside the pipeline.
- PHP 8.5 or newer only The pipe operator is brand new syntax in PHP 8.5. Running this code on PHP 8.4 or earlier will trigger a parse error, so you should only use it in projects where PHP 8.5 is the minimum version.
Where the pipe operator fits in your code
Good places to use the pipe operator:
- Cleaning up and normalizing input strings
- Transforming arrays or API responses in a few simple steps
- Building small, focused data pipelines in service or helper classes
Places where it often adds less value:
- Fluent APIs that already use method chaining
- One line, single function calls that are already obvious
- Complex branching logic where regular control structures read better
As a rule of thumb: if the pipe makes the code easier to read out loud from left to right, it is doing its job.
Final thoughts
The pipe operator in PHP 8.5 is one of those features that feels small on paper but shows up everywhere once you start using it. It encourages a style where you think in terms of simple, reusable transformations and glue them together into a clear sequence.
If you are upgrading to PHP 8.5, start by introducing pipes in small utility and transformation code. After a short time, your older nested calls will begin to look noisy next to the cleaner, left to right pipelines.








