Re: Implicit isset in ternary operator

From: Date: Wed, 18 Jul 2012 19:21:01 +0000
Subject: Re: Implicit isset in ternary operator
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Wed, Jul 18, 2012 at 7:20 AM, Anthony Ferrara <[email protected]>wrote:

>
> On Wed, Jul 18, 2012 at 10:15 AM, Rafael Dohms <[email protected]
> >wrote:
>
> > [...]
> >
> > This is basically because the ternary operator does not do a internal
> > implicit isset, only an empty.
> >
>
> It does not do an empty. Empty would avoid notices as well. All it does is
> an implicit bool cast...
>
>
> > Does this seem like a possible improvement we can work on? Anyone
> > interested in championing the change?
> >
>
> I like it in principle. My only concern is *why* wasn't it done this way in
> the first place... Is there a reason?
>

It changes the semantics. If the variable is set to a falsey value and ?:
uses an implicit isset, the value of the expression will be the falsey
value.

    $config['width'] = ''
    $width = $config['width'] ?: 300
    # $width == ''

If !empty were used instead of isset, you could preserve semantics ($a ?:
dflt = !empty($a) ? $a : dflt).


Thread (31 messages)

« previous php.internals (#61430) next »