Re: PHP7 Coalesce operator
| From: | shadda | Date: | Mon, 23 Nov 2015 19:52:29 +0000 |
| Subject: | Re: PHP7 Coalesce operator | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-89345@lists.php.net to get a copy of this message | ||
Er, that should read, “anything non (null, false, undefined) is true”
> On Nov 23, 2015, at 11:51 AM, shadda <shadda@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 <ajf@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
>>
>