On Sun, Jul 20, 2025, at 5:22 AM, Ilija Tovilo wrote: > Hi Vadim > > Thanks for your follow-up. > > On Sun, Jul 20, 2025 at 11:54 AM Vadim Dvorovenko > <vadim.dvorove...@gmail.com> wrote: >> >> Recently introduced pipeline operator is great, but together with >> assignment operator it will lead to mixing top-to-bottom and >> bottom-to-top code reading directions and vertigo. >> >> To reduce this problem i'd like to discuss the idea of left to right >> assignment operator. The draft rfc can be found here >> https://github.com/vadimonus/php-rfc-pipeline-assignment/blob/main/rfc.md >> , there is the part, that describes problem. > > The problem you're describing is not unique to pipes. Code like this > is quite common. > > $x = foo() > ->bar() > ->baz(); > > If we decide this is a problem (which I fundamentally disagree with), > then we should try to find a general solution, rather than something > that is specific to pipes. There's no reason why this example > shouldn't work. > > foo() > ->bar() > ->baz() |>= $x; > > At that point, you should probably also look for an operator that > isn't pipe-specific. But again, I disagree with the premise that this > is a problem to begin with. > >> The current bahavior of pipe operator when used with variable is wery poorly >> described in RFC > > That's not quite accurate. It states: > >> The left-hand side of the pipe may be any value or expression. > > And according to PHPs expression model, variables get no special > treatment. They are evaluated and the result is used accordingly, > pipes are not special at all in that regard. > > Cheers > Ilija
I am also not a fan of this proposal for much the same reason. First, the mental model it proposes I do not agree with. The model of <variable to assign to> = <arbitrarily complex expression> is fairly universal in PHP and in most languages. It's quite self evident at this point. Furthermore, there are plenty of other "read down and up" use cases beyond pipe. match() and ternaries come to mind as common examples. The behavior of pipes with variables is also very well defined. The left side is any expression (including a variable). The right side is a callable. That callable could be a variable that references a Closure, and often will be. So it's already quite clear what will happen If we were to agree that there was a use case for "reverse assignment" (of which I am not yet convinced), it should be its own stand-alone thing. Just for argument's sake (not actually proposing this): <expression> ==> <variable to assign to> That would then work at the end of a pipe chain, a match statement, a ternary, or whatever else you felt like. Self-contained parts that play well with others are almost always superior to a one-off solution. --Larry Garfield