AW: [PHP-DEV] [RFC] Nullsafe calls
| From: | Robert Stoll | Date: | Wed, 10 Dec 2014 16:20:14 +0000 |
| Subject: | AW: [PHP-DEV] [RFC] Nullsafe calls | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79526@lists.php.net to get a copy of this message | ||
> -----Ursprüngliche Nachricht-----
> Von: Robert Stoll [mailto:php@tutteli.ch]
> Gesendet: Mittwoch, 10. Dezember 2014 17:17
> An: 'Josh Watzman'; 'PHP internals'
> Betreff: AW: [PHP-DEV] [RFC] Nullsafe calls
>
> Hi,
>
> > -----Ursprüngliche Nachricht-----
> > Von: Josh Watzman [mailto:jwatzman@fb.com]
> > Gesendet: Mittwoch, 10. Dezember 2014 00:08
> > An: PHP internals
> > Betreff: [PHP-DEV] [RFC] Nullsafe calls
> >
> > Hey internals! A useful feature that Hack picked up in the last few
> > months are "nullsafe calls", a way of propagating
> failure
> > forward in a series of chained method calls to the end of the whole
> > computation, getting rid of a lot of the
> boilerplate in the
> > middle. I think the feature would be a good one for PHP as well, so
> > I'm submitting this RFC to add it -- you can see
> the RFC
> > itself for a full discussion of the motivation for the feature, as well as the feature
> > itself:
> >
> > https://wiki.php.net/rfc/nullsafe_calls
> >
> > Josh Watzman
> >
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List To unsubscribe,
> > visit: http://www.php.net/unsub.php
>
> First of all, I like the RFC, I think as well that it is a useful feature for PHP and I already
> have it on my wish
list
> ;)
>
> Yet, either I misunderstand the section about short circuiting or I propose to change the
> behaviour.
>
> "If $obj is null, when $obj?->foo(..) executes, the arguments will still be
> evaluated."
>
> IMO that is wrong. It should not evaluate the arguments since the nullsafe operator (sometimes
> called "safe
navigation"
> operator in other languages - which is the better wording IMO, maybe change it? But that is
> just a detail) is just
syntactic
> sugar for making the call only if $bj is not null. So the following:
>
> $obj = null;
> $obj?->foo($a, $b);
>
> should be the same as
>
> $obj = null;
> If($obj !== null){
> $obj->foo($a, $b);
> }
>
> hence PHP will not complain that $a and $b where not defined.
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit:
> http://www.php.net/unsub.php
Appendum: I somehow skipped the section "Prior Art". So I see, that the different
behaviour was on purpose. I do not
think it is a clever idea to implement a common concept differently. In this sense -1
Changing the RFC and implementing it the same way others do +1