Functional Operators
PHP 8.5 and later supports one operator that works directly on callables. The That means the following two lines are logically equivalent. Example #1 Using
The above example will output: 11 11 For a single call that is not especially useful. It becomes useful when multiple calls are chained together. That is, the following two code fragments are logically equivalent: Example #2 Chaining |> calls
The above example will output: Array ( [0] => P [1] => H [2] => P [3] => [4] => R [6] => C [7] => K [8] => S ) Array ( [0] => P [1] => H [2] => P [3] => [4] => R [6] => C [7] => K [8] => S ) The left-hand side of the pipe may be any value or expression. The right-hand side may be any valid PHP callable that takes a single parameter, or any expression that evaluates to such a callable. Functions with more than one required parameter are not allowed and will fail as if the function were called normally with insufficient arguments. Functions that take a variable by reference are not allowed. If the right-hand side does not evaluate to a valid callable it will throw an Error.
See Also
|