Arrow functions on the right hand side of |> must be parenthesized¶
Description¶
The pipe operator accepts many variants of closures, such as closures, callable, arrays and first class callables. Yet, it doesn’t accept direct arrow functions: they must be placed inside parenthesis. This ensures the parser knows when to finish the returned expression, which might also include another pipe operator.
Example¶
<?php
echo 'a' |> fn($a) => 1;
?>
Solutions¶
Use a closure.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.