Re: [RFC] Pipe Assignment Operator

From: Date: Wed, 15 Jul 2026 23:14:05 +0000
Subject: Re: [RFC] Pipe Assignment Operator
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-131952@lists.php.net to get a copy of this message
Hi Nick, On Thu, 16 Jul 2026, 01:30 Nick Sdot, <php@nicksdot.dev> 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

« previous php.internals (#131952) next »