Re:PHP 8.5 Adds Pipe Operator: What it means
by procaryote on Tuesday August 05, 2025 @11:56AM
(#44799690)
Put it in a function and the scope you pollute is only as big as you make it.
Re:PHP 8.5 Adds Pipe Operator: What it means
by hombre_fatal on Tuesday August 05, 2025 @12:08PM
(#44799871)
Functions also pollute the scope the same way. And you don't want to be forced to extract a function that is never reused just to hide intermediate values; you should only have to extract a function when you want the abstraction.
The pipeline transformation specifically lets you clean this up with functions at the scope of each ephemeral intermediate value.
Re:PHP 8.5 Adds Pipe Operator: What it means
by skoskie on Tuesday August 05, 2025 @03:37PM
(#44803188)
That’s why we have classes and namespaces.
Anyone can write good or bad code. Avoiding new functionality and syntax won’t change that.
Re:PHP 8.5 Adds Pipe Operator: What it means
by ckdot on Tuesday August 05, 2025 @04:01PM
(#44803498)
You definitely want to extract code into functions, even if you don’t need to reuse it. Functions names are documentation. And you reduce the mental load from those who read the code.
Re:PHP 8.5 Adds Pipe Operator: What it means
by donatj on Tuesday August 05, 2025 @06:02PM
(#44804991)
If PHP scoped to blocks, it would be less of an issue, you could just wrap your procedural code in curly braces and call it a day
{
$foo = 'bar'; // only defined in this block
}
I use this reasonably often in Go, I wish it were a thing in PHP. PHP allows blocks like this but they seem to be noops best I can tell.
You might have $values and then you transform it into $b, $values2, $foo, $whatever, and your code has to be eternally vigilant that it never accidentally refers to $values or any of the intermediate variables ever again since they only existed in service to produce some downstream result.
Sometimes this is slightly better in languages that let you repeatedly shadow variables, `$values = xform1($values)`, but we can do better.
That it's hard to name intermediate values is only a symptom of the problem where many intermediate values only exist as ephemeral immediate state.
Pipeline style code is a nice general way to keep the top level clean.