On Fri, Apr 15, 2011 at 8:46 PM, Ben Schmidt
<mail_ben_schm...@yahoo.com.au>wrote:

> There was also my suggestion of a "checked ternary" operator [see my
>> previous email in this thread.] Backwards compatible, practical, and
>> simple.
>>
>
> It doesn't address the main issues of code duplication and nullness
> checking, IMHO, so isn't a contender. Even though it's simple and
> compatible, it is only practical in a handful of cases.
>

I believe describing nullness checking as a "main" issue is a rather strong
assessment.

David's original message and patch (and several of the suggestions in this
thread) speak to the issues with boilerplate code needed to avoid warnings
elicited when accessing a non-existant array key. This is the type of code
that you tend to see out in the wild that David and others have cited as a
pain:

$var = (isset($arr['key'])) ? $arr['key'] : 'empty';

Additionally, it might not be as succinct as you prefer, but surely

$var = $arr['key'] ?? : 'empty';

is a significant improvement over the current means and does in fact remove
redundant code.

Now, perhaps there are other options that are better. This is an interesting
dialogue to follow, and I've enjoyed the reading. However, after viewing the
other proposals thus far, my preference would still be for the checked
ternary operator.

Respectfully,

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

Reply via email to