Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51839 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54438 invoked from network); 8 Apr 2011 13:57:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2011 13:57:33 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:50223] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/84-17421-9441F9D4 for ; Fri, 08 Apr 2011 09:57:33 -0400 Received: by wyb34 with SMTP id 34so3343338wyb.29 for ; Fri, 08 Apr 2011 06:57:27 -0700 (PDT) Received: by 10.227.0.140 with SMTP id 12mr2262584wbb.122.1302271046766; Fri, 08 Apr 2011 06:57:26 -0700 (PDT) Received: from [192.168.80.137] (77-58-253-248.dclient.hispeed.ch [77.58.253.248]) by mx.google.com with ESMTPS id w12sm1727069wby.24.2011.04.08.06.57.25 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Apr 2011 06:57:25 -0700 (PDT) Message-ID: <4D9F144A.9030600@seld.be> Date: Fri, 08 Apr 2011 15:57:30 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: internals@lists.php.net References: <4D950434.3060704@yahoo.com.au> <4D9E0543.1080600@lerdorf.com> <69.82.36433.EC33E9D4@pb1.pair.com> <4D9E34C4.5000406@lerdorf.com> <4D9E429B.20503@sugarcrm.com> <4D9E96B6.6060401@lerdorf.com> In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: j.boggiano@seld.be (Jordi Boggiano) 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/