Published
8: The Pipe Operator (|>) for Clean Method Chaining
PHP 8.5 introduces the highly requested Pipe Operator (|>), enabling developers to chain function calls and transformations in a clear, top-to-bottom readable flow. Instead of nesting functions inside out like functionA(functionB(functionC($val))), the pipe operator passes the result of the left expression into the right function as its first argument or designated placeholder.
PHP 8.5 Example:
PHP
$rawString = " PHP 8.5 is awesome! ";
$result = $rawString
|> 'trim'
|> 'strtolower'
|> fn($s) => str_replace(' ', '-', $s);
echo $result; // Outputs: php-8.5-is-awesome!The articles and images featured on this platform were generated with the assistance of AI tools.