Well use null coalesce + elvis together then?

// Coalesce possible null values, and use truthy comparison in elvis to
"coalesce" to a default
$var = ($_GET['possible_value'] ?? $_COOKIE['secondary'] ?? false) ?:
DEFAULTS['var'];

On Mon, Nov 23, 2015 at 1:16 PM, shadda <sha...@gmail.com> wrote:

> It’s not hate, I happen to like that ?? was added. I’m not raising a
> concern nor asking for a change in its behavior. Rather, I’m asking for
> another, similar operator that’s based on truth-evaluation (with PHP’s
> tender, loving conversion rules baked in), in *addition* to ?? which tests
> for null/undefined exclusively.
>
>
> > On Nov 23, 2015, at 12:08 PM, Phil Sturgeon <pjsturg...@gmail.com>
> wrote:
> >
> > On Mon, Nov 23, 2015 at 9:52 AM, shadda <sha...@gmail.com> wrote:
> >> Er, that should read, “anything non (null, false, undefined) is true”
> >>
> >>> On Nov 23, 2015, at 11:51 AM, shadda <sha...@gmail.com> wrote:
> >>>
> >>> Hey, thanks for responding.
> >>>
> >>> However, I still think that misses the point, or at least the true
> utility of what I’m proposing.
> >>>
> >>> 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.
> >>>
> >>> Basically in ECMA, anything non-null, false, or undefined is true. PHP
> is very similar in that regard, but our reliance on E_NOTICE to (ahem)
> enforce isset() checks is why, I assume, we’re introducing the ?? operator
> to begin with.
> >>>
> >>> I just think it’d be nice to have a small variation on this feature
> that was less concerned with a (defined|null) semantic and more in keeping
> with PHP’s overall handling of implicit type conversion in expressions.
> >>>
> >>> Does that make more sense?
> >>>
> >>>> On Nov 22, 2015, at 12:41 PM, Andrea Faulds <a...@ajf.me> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> shadda wrote:
> >>>>> I had a question-suggestion based around the cool new operator we’re
> getting in PHP7, the ?? operator, which as I understand it is the
> functional equivalent to perl’s // operator; in that they both test for
> whether or not a variable is defined, rather than it’s truthiness.
> >>>>
> >>>> This is not strictly correct. Though something of a misnomer, the
> 'null coalesce operator' checks if a variable doesn't exist, but also that
> it is not null, i.e. it functions like isset().
> >>>>
> >>>> Thanks.
> >>>>
> >>>> --
> >>>> Andrea Faulds
> >>>> http://ajf.me/
> >>>>
> >>>> --
> >>>> PHP Internals - PHP Runtime Development Mailing List
> >>>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>>
> >>>
> >>
> >>
> >> --
> >> PHP Internals - PHP Runtime Development Mailing List
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
> > Ignoring E_NOTICE is generally considered bad practice by many, and
> > turning them off just to use ternaries instead of null coalesce (a
> > feature we already have) doesn't seem like a benefit.
> >
> > The ?? is used the same as "a = b || c" in Ruby or JS. Doing that in
> > PHP wouldn't work well as || works a bit differently, so ?? is used
> > instead, just like C and Swift.
> >
> > Basically... it's all good. And even if you hate it you're months too
> > late to raise a concern. :)
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to