Re: [RFC] anti-coalescing-operator

From: Date: Fri, 25 Oct 2019 10:20:43 +0000
Subject: Re: [RFC] anti-coalescing-operator
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-107692@lists.php.net to get a copy of this message
On Thu, 24 Oct 2019 at 22:20, Kosit Supanyo <webdevxp.com@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". Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#107692) next »