On Dec 10, 2014, at 8:17 AM, Robert Stoll <p...@tutteli.ch> wrote: > 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: > > [...] >
Take a look at the "short circuit" section where I specifically address this. It was done to make it easier to reason about in a side-effect-ful language like PHP. With this behavior, when you see $x?->f(g(), h()) you don't have to worry about thinking whether g() and h() will actually be evaluated or not -- only the call to f() itself, which is explicitly marked as nullsafe (i.e., might not happen). It also comes down to what you mean by "not making the method call when $x is null" -- we in fact don't make the method call, but we still prepare everything as if we were going to, and just decide not to do it at the last moment. I feel pretty strongly that this is the correct behavior. It may sound strange when talking about isolated examples like this, but in the real-world code I've seen, it is the least confusing. (I'll see if I can dig up a better example instead of just citing nebulous "real-world code" ;)) Josh -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php