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".


Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to