Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51835 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18104 invoked from network); 8 Apr 2011 07:32:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2011 07:32:49 -0000 Authentication-Results: pb1.pair.com header.from=dukeofgaming@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=dukeofgaming@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: dukeofgaming@gmail.com X-Host-Fingerprint: 74.125.83.170 mail-pv0-f170.google.com Received: from [74.125.83.170] ([74.125.83.170:54586] helo=mail-pv0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/00-17421-F1ABE9D4 for ; Fri, 08 Apr 2011 03:32:48 -0400 Received: by pvg16 with SMTP id 16so1313656pvg.29 for ; Fri, 08 Apr 2011 00:32:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=J40T5ipITruz2tezxIMSEFLOLsNEkaEU0XK8LWLUFjI=; b=RehGtbEI6prIpVVI7dCm8N7v1rICWJ/anHV3rLbOIoF6qV7UBcncqI6ESQJcdc8NL1 RSq5WAHvXvrirtnlomvQV4n9A1UqZUxAgAJfbWV4aejYZOSeuocA6IfI68ebxX5jf6tS 1tm4Euma88CEz53lVidBZwjwj8lBRNsEZ68Xg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=UNZaz5VcKZ5teMGorrJ7YjVLnkO6r41wgpwlT7MGwpYYZSmbSKtxWTMlvd0hwj8WwV EUckwcR3NUmXOmGz8gxatHvcu4q6n9PCnXeu7QpPacuNfDWwKwE7Koihgizn+Zt5D9dD H5mUZY/Fia9TyNH3ezL8b1oGg8wU6gUL3wzpc= Received: by 10.142.178.17 with SMTP id a17mr1525436wff.65.1302247949110; Fri, 08 Apr 2011 00:32:29 -0700 (PDT) MIME-Version: 1.0 Received: by 10.68.42.73 with HTTP; Fri, 8 Apr 2011 00:32:09 -0700 (PDT) In-Reply-To: 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> Date: Fri, 8 Apr 2011 02:32:09 -0500 Message-ID: To: Adam Richardson Cc: PHP Development Content-Type: multipart/alternative; boundary=000e0cd2df946a8e7404a0633ad8 Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: dukeofgaming@gmail.com (dukeofgaming) --000e0cd2df946a8e7404a0633ad8 Content-Type: text/plain; charset=ISO-8859-1 Hi, just to drop an opinion on something I felt natural when reading this: how about a word instead?: $value = 'Not set' unless $a['key']; I think it would be way more readable. Regards, David On Fri, Apr 8, 2011 at 2:02 AM, Adam Richardson wrote: > > > > > >> We need to be careful about changing the beahviour of existing > > operators. > > > > Indeed. > > The '?' character already is special, so using '??' seems like a safe, > practical approach. However, I'd prefer maintaining the form of the > standard > ternary operator with the colon ($value = $var['bar'] ?? : 'Bar was not > set'; // value ="Bar was not) so the '??' operator could be applied in any > situation that one would normally use the standard ternary operator. > > // standard > $value = isset($a[$key]) ? $a[$key] : 'Not set'; > > // new ?? double ternary that performs isset check and omits second > expression > $value = $a[$key] ?? : 'Not set'; > > // new ?? double ternary that performs isset check and uses second > expression > $value = $a[$key] ?? strtoupper($a[$key]) : 'Not set'; > > Granted, the last example might be infrequent, but I think there's also a > value in keeping the form of the double ternary (if used at all) the same > as > the standard ternary operator for consistency sake. > > Adam > > -- > Nephtali: A simple, flexible, fast, and security-focused PHP framework > http://nephtaliproject.com > --000e0cd2df946a8e7404a0633ad8--