Re: [RFC] Pipe Operator (again)

From: Date: Fri, 07 Feb 2025 23:35:52 +0000
Subject: Re: [RFC] Pipe Operator (again)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message


On Sat, Feb 8, 2025, at 00:19, Larry Garfield wrote:
> On Fri, Feb 7, 2025, at 4:54 PM, Rob Landers wrote:
> 
> > Put another way, what is the order of operations for this new operator?
> >
> > For example, what is the output of
> >
> > $x ? $y |> strlen(…) : $z
> >
> > $x + $y |> sqrt(…) . EOL
> >
> > Etc.
> >
> > I noticed this seems to be missing from the RFC. As a new operator, I 
> > think it should be important to specify that. 
> >
> > — Rob
> 
> Pipe deliberately binds fairly low, so most other operators will happen first.  Including +, ??
> and ? :, for which there are tests:
> 
> https://github.com/php/php-src/pull/17118/files#diff-81789df7e324801626ef4ef8f629cc95dceed4c09073a2b58b70c811bf776904
> 
> https://github.com/php/php-src/pull/17118/files#diff-56cbcf85bd7f68fa7a1f837eb15dcc536576986f366976f9642ad20867c471fd
> 
> https://github.com/php/php-src/pull/17118/files#diff-775c14f54cd1a27719d30bfab62024aeb1625bc3f3621fa0e7c16fb1c7957fdd
> 
> So in the examples above, the second would add $x and $y first, then square-root the result. 
> The first, I think would probably need parens to avoid being invalid but I'd have to try it to
> be sure.
> 
> --Larry Garfield
> 

It might be good to specify it in the RFC so if there are any strange behavior, decades from now,
there will be an intent to figure out if it is a feature or a bug. 

As to the ternary, it is the difference between that example being valid and this $x |> $x
> 3 ? foo(…) : bar(...) |> baz(…) making sense or not. Personally, I wouldn’t
write this code and would use parens to disambiguate, but it’d be handy to know when doing code
reviews of authors who don’t.

— Rob


Thread (38 messages)

« previous php.internals (#126345) next »