Pipe operator в PHP 8.5: реальные примеры использования
PHP 8.5 added the pipe operator |>. Arrow functions on the right side must be wrapped in parentheses.
Basic syntax: $value |> (fn($x) => someFunction($x)). The value on the left is passed as the argument to the callable on the right.
String transformation example:
Named functions do not need parentheses since they are not arrow functions:
The parenthesis requirement applies only to arrow functions and closures, not to first-class callable syntax like trim(...).
Tested in sandbox. The parentheses around arrow functions are required in PHP 8.5, otherwise you get a fatal error. Here is a practical example with input sanitization:
And numeric transformations:
Readability improves noticeably when there are more than four steps. The parentheses add some noise but it is still cleaner than deeply nested calls.
```php blocks are runnable.