On 08.04.2011 15:19, Rune Kaagaard wrote:
> New syntax:
>     // a)
>     $a = get_stuff('foo') ?? 42;
> 
>     // b)
>     $a = get_stuff('foo') ?! 42;

This is wrong. The "new syntax" is already available since 5.3.0 and is

$a = get_stuff('foo') ?: 42;

Now I agree with you, it sounds great and all, but we have to be clear:

$a ?: $b  =>  $a ? $a : $b

And ?? should equal to !empty($a), or otherwise said isset($a) && $a
So:

$a ?? $b  =>  (isset($a) && $a) ? $a : $b

Again, your example1 was unclear. !empty is not the equivalent of
isset(). They only are equal if the value is null, but not for false or
"" or array().

Seeing how everyone says confusing stuff here, I'm starting to think
those shortcuts may actually be more harmful than anything.

I'd just favor switching ?: to be equivalent to !empty() instead of just
a cast to boolean, because it means we can drop the isset checks, and
the semantics wouldn't change - only BC "break" would be warnings going
away. The rest, adding new operators, is dangerous imo.

Cheers

-- 
Jordi Boggiano
@seldaek :: http://seld.be/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to