• Introducing the Pipe Operator in PHP 8_415.jpg

    Introducing the Pipe Operator in PHP 8.5

    With the upcoming release of PHP 8.5 (scheduled for November 20, 2025), a new pipe operator (|>) makes it possible to chain first-class callables in a functional, left-to-right style. This design simplifies nested calls, improves readability, and retains performance similar to traditional nested code

     

    What It Does

    • Takes the output of the expression on the left side

    • Passes it as the first (and only) parameter to the callable on the right side

    • Evaluates left-to-right, making chained transformations easier to follow




    Example Usage


     $result = "Hello World"
    |> strtoupper(...)
    |> str_shuffle(...)
    |> trim(...);


    This is functionally equivalent to:

    $result = trim(str_shuffle(strtoupper("Hello World")));

     

    Important Constraints

    1. Callables must accept exactly one required parameter
      If a callable expects multiple parameters or none at all, the pipeline will either error or silently drop parameters php.net.

    2. By-reference parameters usually not supported
      Most functions expecting parameters by reference won't work in the pipe chain (some exceptions like extract() and array_multisort() exist) Reddit+3PHP.Watch+3SensioLabs+3.

    3. Return type void becomes null
      Any callable with a void return will result in null for the rest of the chain.

    4. Precedence rules
      The pipeline evaluates left-to-right, unless overridden with parentheses; it behaves predictably with other operators like +, ??, and the ternary operato






    Real‑World Example


    $fullName = 'Fred Flintstone';

    $result = $fullName
    |> fn($x) => explode(' ', $x) // ['Fred', 'Flintstone']
    |> fn($x) => implode('_', $x) // 'Fred_Flintstone'
    |> strtolower(...); // 'fred_flintstone'

    echo $result;

     Why It Matters

    • Cleaner, expressive syntax — no nested parentheses or temporary assignments

    • Easier to read — supports point‑free and pipeline-style code

    • Efficient execution — similar performance to nested calls due to VM optimizations