Re: [PHP-DEV] [RFC] Pipe Assignment Operator
[email protected] (Alex Pătrănescu) Thu, 16 Jul 2026 02:14:05 +0300
| Newsgroups | php.internals |
|---|---|
| Message-ID | <CAAwdEzB+rpxNurRN0obnD=jPJZ-qL+2MyES+sxtqroHzBMH1Xw@mail.gmail.com> |
Hi Nick, On Thu, 16 Jul 2026, 01:30 Nick Sdot, <[email protected]> wrote: > > > // before > public function makeSlug(string $value): string { > $value = $value |> mb_strtolower(...); // ... > $number = $this->getNextSlugNumber($value); // checks DB > if (0 < $number) { $value .= "-$number"; } > return $value; > } > > // after > public function makeSlug(string $value): string { > $value |>= mb_strtolower(...) ; // ... > $number = $this->getNextSlugNumber($value); // checks DB > if (0 < $number) { $value .= "-$number"; } > return $value; > } > > > Currently we have to make assignment gymnastics even for use cases that > do not require an immutable second value. Would argue many people in PHP > do and will use pipes for readability, not because they suddenly write > PHP from a functional programming point of view. This is a good > proposal, IMO. > > I would argue that is a very bad practice in php, to alter the actual function parameter variable. That is because any stack trace obtained will not reflect the initial value but the modified value. And generally, it is a bad practice to override a variable with some other value that represents something different. You could have had incrementally: $lowercaseValue, and $slug/$valueWithSlugNumber. -- Alex