On Fri, 25 Oct 2019 at 12:27, Andreas Hennings <andr...@dqxtech.net> wrote: > > On Fri, 25 Oct 2019 at 12:21, Rowan Tommins <rowan.coll...@gmail.com> wrote: > > > > On Thu, 24 Oct 2019 at 22:20, Kosit Supanyo <webdevxp....@gmail.com> wrote: > > > > > But I think this functionality should be of something like pipeline > > > operator: > > > > > > // send tmp variable to the next expression unconditionally > > > $ret = $_SERVER['fname'] |> $user->setName($$); > > > // send tmp variable to the next expression only when $_SERVER['fname'] is > > > set. > > > $ret = $_SERVER['fname'] ?|> $user->setName($$); > > > > > > Also the syntax like above will be consistent with the proposed > > > safe-navigation operators. > > > > > > > > > I really like this idea, and it actually makes the pipeline operator itself > > feel more useful, too. > > > > Imagine this chain, where not only might the variable not be set, but it > > might not match a user, or the user might have no name: > > > > $upperCaseUserName = $_GET['user_id'] ?|> User::getById($$) ?-> getName() > > ?|> strtoupper($$); > > > > As well as not needing to repeat the expression each time, as you would > > with an "anti-coalesce", "null-safe chain" feels a clearer reading of the > > intent here than "if not unset". > > I like this. > It is a bit like a temporary local variable. > > One limitation is that you only have one such pipe value at a time. > E.g. it would not cover this: > > return isset($a, $b) ? foo($a, $b) : null; > > or any nested parameters like foo(bar(baz())) where any intermediate > value could be null.
Sorry, this last part is wrong of course. The pipe works great for nested calls. Just with multiple parameters which all can be null it does not. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php