News for hackers. Stuff that matters.
Re:PHP 8.5 Adds Pipe Operator: What it means by wouldbecouldbe on Tuesday August 05, 2025 @01:17AM (#44794547)
It’s really not needed, syntax sugar. With dots you do almost the same. Php doesn’t have chaining. Adding more and more complexity doesn’t make a language better.
Re:PHP 8.5 Adds Pipe Operator: What it means by bapak on Tuesday August 05, 2025 @01:24AM (#44794576)
Nothing is really needed, C89 was good enough.

Dots are not the same, nobody wants to use chaining like underscore/lodash allowed because it makes dead code elimination impossible.

Re:PHP 8.5 Adds Pipe Operator: What it means by pjmlp on Tuesday August 05, 2025 @03:30AM (#44795277)
K&R C was good enough for UNIX System V, why bother with C89.
Re:PHP 8.5 Adds Pipe Operator: What it means by boobsbr on Tuesday August 05, 2025 @05:14AM (#44795897)
K&R C was the apex, we've just been going downhill since.
Re:PHP 8.5 Adds Pipe Operator: What it means by lioeters on Tuesday August 05, 2025 @11:47AM (#44799542)
This but unironically.
Re:PHP 8.5 Adds Pipe Operator: What it means by troupo on Tuesday August 05, 2025 @01:40AM (#44794665)
> With dots you do almost the same.

Keyword: almost. Pipes don't require you to have many different methods on every possible type: https://news.ycombinator.com/item?id=44794656

Re:PHP 8.5 Adds Pipe Operator: What it means by EGreg on Tuesday August 05, 2025 @01:22AM (#44794567)
It’s not really chaining

More like thenables / promises

Re:PHP 8.5 Adds Pipe Operator: What it means by wouldbecouldbe on Tuesday August 05, 2025 @01:25AM (#44794577)
It looks like chaining, but with possibility of adding custom functions?
Re:PHP 8.5 Adds Pipe Operator: What it means by bapak on Tuesday August 05, 2025 @01:59AM (#44794754)
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
Re:PHP 8.5 Adds Pipe Operator: What it means by cyco130 on Tuesday August 05, 2025 @02:19AM (#44794848)
It requires parentheses `(3).myMethod()` but you can by monkey patching the Number prototype. Very bad idea, but you absolutely can.
Re:PHP 8.5 Adds Pipe Operator: What it means by senfiaj on Sunday August 10, 2025 @10:59AM (#44855633)
You can just add extra dot: `3..myMethod()`.
Re:PHP 8.5 Adds Pipe Operator: What it means by EGreg on Tuesday August 05, 2025 @10:20AM (#44798311)
Not only that

In chaining, methods all have to be part of the same class.

In C++ we had this stuff ages ago, it’s called abusing streaming operators LMAO

Re:PHP 8.5 Adds Pipe Operator: What it means by te_chris on Tuesday August 05, 2025 @02:21AM (#44794854)
Dots call functions on objects, pipe passes arguments to functions. Totally missing the point.
Re:PHP 8.5 Adds Pipe Operator: What it means by Martinussen on Tuesday August 05, 2025 @05:37AM (#44796031)
When you say chaining, do you mean autoboxing primitives? PHP can definitely do things like `foo()->bar()?->baz()`, but you'd have to wrap an array/string yourself instead of the methods being pulled from a `prototype` to use it there.
Re:PHP 8.5 Adds Pipe Operator: What it means by chilmers on Tuesday August 05, 2025 @05:58AM (#44796171)
I'm tired of hearing the exact same arguments, "not needed", "just syntax sugar", "too much complexity", about every new syntax feature that gets added to JS. Somehow, once they are in the language, nobody's head explodes, and people are soon using them and they become uncontroversial.

If people really this new syntax will make it harder to code in JS, show some evidence. Produce a study on solving representative tasks in a version of the language with and without this feature, showing that it has negative effects on code quality and comprehension.

Re:PHP 8.5 Adds Pipe Operator: What it means by robertlagrant on Tuesday August 05, 2025 @07:44AM (#44796882)
Presumably it's up to the change proposers to produce said study showing the opposite.
Re:PHP 8.5 Adds Pipe Operator: What it means by purerandomness on Tuesday August 05, 2025 @06:34AM (#44796392)
If your team prefers not to use this new optional feature, just enable a PHPStan rule in your CI/CD pipeline that prevents code like this getting merged.
Re:PHP 8.5 Adds Pipe Operator: What it means by hajile on Tuesday August 05, 2025 @12:10PM (#44799906)
Chaining requires creating a class and ensuring everything sticks to the class and returns it properly so the chain doesn't blow up. As you add more options and do more stuff, this becomes increasingly hard to write and maintain.

If I'm using a chained library and need another method, I have to understand the underlying data model (a leaky abstraction) and also must have some hack-ish way of extending the model. As I'm not the maintainer, I'm probably going to cause subtle breakages along the way.

Pipe operators have none of these issues. They are obvious. They don't need to track state past the previous operator (which also makes debugging easier). If they need to be extended, look at your response value and add the appropriate function.

Composition (whether with the pipe operator or not) is vastly superior to chaining.