Re: A little syntactic sugar on array_* function calls?

From: Date: Tue, 25 May 2021 10:40:37 +0000
Subject: Re: A little syntactic sugar on array_* function calls?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-114580@lists.php.net to get a copy of this message
Thanks for your quick feedback everyone. On Tue, May 25, 2021 at 3:22 AM someniatko <someniatko@gmail.com> wrote: > > The pipe operator feels like a poor solution while -> > > would do exactly > what people want. > > Could you elaborate? Adding method-like array access functions with > only few predefined functions, and only for arrays looks very limited > That is probably because it is very limited :) deliberately so. The proposed syntax $array |> array_map($fn1, ?) |> array_filter(?, $fn2) When I compare to: $array->map($fn1)->filter($fn2) 1. It's longer. Much longer. 2. It still requires knowing where the array goes. That's legacy which we could sidestep with the arrow notation. 3. Admittedly, the pipe is much more powerful. But why not both :) ? Also, it would require accepting two RFCs although of course mine would need to become an RFC too and longer term this is not a problem. scalar_objects are wonderful. It's a space rocket compared to my wheelbarrow. If it flies , mine is obviously moot. However, a wheelbarrow is much cheaper and quicker to construct than a spaceship :D Once again, what I propose here wants to be a simple, cheap to implement, narrow quickfix. (Although users can add array_foobar($array, $arg1...) for $array->foobar($arg1) as they need.) Karoly Negyesi

« previous php.internals (#114580) next »