Live data from Hacker News

PHP 8.5 adds pipe operator

thephp.foundation

281–282 of 282 posts

Re: PHP 8.5 adds pipe operator

#281

Earlier quoted context omitted.

Basically what Collections do in Laravel.

Exactly... similar in Symfony. While converting arrays to collection-object is a suitable option that does work, it would feel much more "native", if there were extension methods for Iterable / Traversable.

Agreed. Like in JS and Java, it would be a lot nicer if the language itself had the chainable methods.

Re: PHP 8.5 adds pipe operator

#282
post #20
post #13

Earlier quoted context omitted.

It's chaining without having to vary the return of each function. In JS you cannot call 3.myMethod(), but you could with 3 |> myMethod

It requires parentheses `(3).myMethod()` but you can by monkey patching the Number prototype. Very bad idea, but you absolutely can.

You can just add extra dot: `3..myMethod()`.
Post reply on HN