PHP 8.5 introduces the pipe operator `|>`, which passes the result of the left-hand expression as the first argument to the callable on the right. The classic example is input sanitization: instead of nesting `strtolower(str_replace(..., trim($input)))`, which reads in reverse execution order, developers can now write the chain left to right.
<?php
function makeSlug(string $input): string
{
return $input
|> trim(...)
|> (fn($s) => str_replace(' ', '-', $s))
|> strtolower(...)
|> (fn($s) => preg_replace('/[^a-z0-9-]+/', '', $s));
}The operator requires a callable on the right side, not an immediate function call. For single-argument functions this uses PHP 8.1's first-class callable syntax: `trim(...)` creates a closure, while `trim()` would execute immediately and fail. The compiled opcodes match those of nested calls, so there is no runtime overhead.
Functions needing more than one argument must be wrapped in arrow functions, and those arrow functions require parentheses to avoid parse errors. The author notes this verbosity is the most common complaint, and PHP 8.6 is expected to add partial function application to address it.
Instance methods cannot be piped directly and need arrow function wrappers, while static methods work with first-class callable syntax. Void functions like `var_dump` break chains by passing null to the next step. The syntax is not backward compatible with PHP 8.4 or older. PhpStorm and VS Code with Intelephense already support it.




Comments
No comments yet — be the first.
Open the discussion
No account or password needed — just enter your e-mail and we’ll send you a one-time sign-in link. First time here? You’re set up automatically.
Your rating will be applied automatically after you sign in.
Check your inbox
We’ve sent a sign-in link to …. Open it on this device — this tab will sign you in automatically.
Nothing arrived? Check your spam folder — and mark the mail as "Not spam" so it lands in your inbox next time.