Re: PHP7 Coalesce operator
| From: | shadda | Date: | Mon, 23 Nov 2015 20:12:22 +0000 |
| Subject: | Re: PHP7 Coalesce operator | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-89348@lists.php.net to get a copy of this message | ||
Oh, please, by no means take that as an endorsement for dropping error reporting levels. It was just
an observation of how PHP actually derives a conditional in those situations. It’s not as if
there’s a fatality in script execution when you make that kind of comparison, it’s just a really
shitty way to code. In fact, it’s also why i typically avoid empty(). Nevertheless, PHP lacks a
concise solution for dealing with multiple possibly-false-evaluating values.
Hacks like my coalesce() function that rely on the side effect of reference-passing can only go so
far, as there’s also no way to pass &N references (at least that I’m aware of, correct me if
I’m wrong)
I mean really I just want to be able to easily and lazily handle situations where I’ve got several
vars as possible values in an assignment or expression, without chaining lots of function calls.
Perhaps if empty() took N params like isset() does, but that’s only a nudge in the, er,
“right” direction.
> On Nov 23, 2015, at 12:03 PM, Levi Morrison <levim@php.net> wrote:
>
>> In practice, you can ignore E_NOTICE and php will happily treat null and !isset() as the
>> same thing in *most* cases, so that’s not a good indicator of truthiness.
>
>
> If you really believe that then this is all you need already:
>
> $database = $config['database'] ?: 'db';
>
> Correct?