✨ PHP 8.5's new operator will change the way you code
on July 6, 2025
PHP 8.5 is just around the corner, and with it comes a long-awaited addition: the pipe operator (|>
). This seemingly small feature might have a huge impact on how we write and structure our code—especially for developers who lean toward a more functional style.
In this article, I’ll explain what the pipe operator does, why it matters, and how you can start using it to write cleaner, more expressive PHP. We'll also look at practical examples and some caveats to keep in mind.
💡 What Is the Pipe Operator?
The pipe operator allows you to pass a value to a function as its first argument, making function chaining much more readable.
Here’s a quick example:
$string = " Hello World "
|> trim(...)
|> strtolower(...)
|> fn($string) => str_replace(' ', ' ', $string);
This is equivalent :
$string = " Hello World ";
$string = trim($string);
$string = strtolower($string);
$string = str_replace(' ', '-', $string);
It’s the same logic—but way more expressive.
🧠 Why It Matters
The pipe operator brings several benefits:
- ✅ Improved readability: Less nesting, more clarity.
- ✅ Encourages smaller, pure functions: Perfect for data pipelines.
- ✅ Moves PHP closer to functional programming concepts.
- ✅ Comes with compiler-level optimization for performance.
In short: it’s more elegant, less verbose, and aligns PHP with modern programming paradigms.
🚫 Limitations to Know
Before you go rewriting your entire codebase, here are a few gotchas:
- It only works with functions that accept a single argument.
- It does not support arguments passed by reference.
- It’s currently not compatible with multiple-parameter functions unless partially applied (which isn’t yet part of PHP natively).
But for common transformations—strings, arrays, filtering, formatting—it’s perfect.
🧪 Project source code
You can find the source code of this video: https://github.com/matyo91/php-pipe-operator
🚀 What's Next?
PHP 8.5 is set for official release in November 2025. Until then, you can try it by compiling PHP from source or using a Docker image from the nightly builds.
⚙️ Bonus: Automate Your Dev Workflows
If you’re interested in automating your development workflows (like generating content, syncing code, or publishing releases), check out Uniflow — the no-code orchestration platform I’m building.
It integrates perfectly with PHP-based tools and lets you build automations using a visual flow editor — no extra boilerplate needed.