▲ | hombre_fatal 7 days ago | ||||||||||||||||||||||
The problem with intermediate assignment is that they pollute your scope. 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. | |||||||||||||||||||||||
▲ | donatj 7 days ago | parent | next [-] | ||||||||||||||||||||||
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
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. | |||||||||||||||||||||||
▲ | procaryote 7 days ago | parent | prev [-] | ||||||||||||||||||||||
Put it in a function and the scope you pollute is only as big as you make it. | |||||||||||||||||||||||
|