On Fri, 25 Oct 2019 at 03:37, Ken Stanley <doh...@gmail.com> wrote:

> This got rejected for being too large???
>


If you trim the quotes in your replies to just the parts needed for
context, it keeps the message shorter, and makes it much easier to read
through.




> > The fact that it’s a counterpart to an existing syntax l, I believe,
> > further warrants it’s inclusion into the language.
>


As I mentioned before, it doesn't feel to me a very natural complement. The
use cases for the new operator don't feel like "the negation" of the use
cases for the existing ?? operator, and although different from null-safe
calls, have more in common with them than "coalescing".




> >> The repetition becomes more relevant if the expression we would repeat
> >> is really long:
> >>
> >> isset($something['something']['something']['something']) !??
> >> $something['something']['something']['something']->foo();
> >
> >
> > This would be invalid because isset() returns Boolean



I suspect that was just a mistake; the point was the new operator doesn't
save any repetition in an expression such as:

$something['something']['something']['something'] !??
$something['something']['something']['something']->foo();

Which in this particular case could be rewritten if we had a null-safe call
operator, and would gain a lot more readability:

$something['something']['something']['something']?->foo();




> > As far as flow control, let’s make no mistake, ??, ?:, and the idea of
> !??
> > are all succinct forms of flow control. To pretend otherwise is a bit
> > naive.
>


I think you're misunderstanding what people mean by "flow control"; the key
point is whether you're using the operator to obtain a value, or to trigger
a side effect.

For instance, this would not generally be considered "flow control":

$x = $someFlag ? 1 : 2;

Yes, strictly speaking, you're selecting one of two paths, but the only
side-effect is an assignment, outside the expression. Compare to this,
where the value of the expression is never even used, and you're just
choosing a side-effect:

$someFlag ? deleteUser() : logOut();



Your second example was better in this respect, because it used the result:

$user = $application->getUser() !?? $this->getUser();

However, is this actually the desired code? If I'm not mistaken, it would
de-sugar to this:

if ( isset($application->getUser() ) {
    $user = $this->getUser();
} else {
    $user = null;
}

Given that your specified aim is to look up a default, isn't this actually
a case for the existing null-coalesce operator?

$user = $application->getUser() ?? $this->getUser();
// or if the precedence is the other way around:
$user = $this->getUser() ?? $application->getUser();



Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to