Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51825 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 31662 invoked from network); 7 Apr 2011 18:30:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2011 18:30:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=listas@rafaeldohms.com.br; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=listas@rafaeldohms.com.br; sender-id=unknown Received-SPF: error (pb1.pair.com: domain rafaeldohms.com.br from 74.125.83.42 cause and error) X-PHP-List-Original-Sender: listas@rafaeldohms.com.br X-Host-Fingerprint: 74.125.83.42 mail-gw0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:33344] helo=mail-gw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/B9-02627-EA20E9D4 for ; Thu, 07 Apr 2011 14:30:07 -0400 Received: by gwb17 with SMTP id 17so1149691gwb.29 for ; Thu, 07 Apr 2011 11:30:03 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.191.133 with SMTP id g5mr1566395yhn.69.1302201003561; Thu, 07 Apr 2011 11:30:03 -0700 (PDT) Received: by 10.147.39.13 with HTTP; Thu, 7 Apr 2011 11:30:03 -0700 (PDT) In-Reply-To: <4D950434.3060704@yahoo.com.au> References: <4D950434.3060704@yahoo.com.au> Date: Thu, 7 Apr 2011 15:30:03 -0300 Message-ID: To: Ben Schmidt Cc: David Coallier , internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: listas@rafaeldohms.com.br (Rafael Dohms) On Thu, Mar 31, 2011 at 7:46 PM, Ben Schmidt wrote: > On 1/04/11 3:29 AM, David Coallier wrote: >> >> Hey there, >> >> I've been working on a little patch that will allow variables ($1) in >> a short-ternary operation to go through an implicit isset >> (zend_do_isset_or_isempty) check so that the average use-case for the >> short-ternary operator doesn't yield in a notice whenever the first >> variable of the expression isn't set. >> >> So the use-case I'm considering is the following: >> >> > =A0 =A0 $list =3D array('name' =3D> =A0'list'); >> >> =A0 =A0 echo $list['name'] ?: 'List not set.' . PHP_EOL; >> =A0 =A0 echo $list['name-notset'] ?: 'List not set.' . PHP_EOL; >> ?> >> >> This example, which we all know, will result in a notice for the >> second echo statement because the requested array-key doesn't actually >> exist in the array. > > I'm not familiar with the construct, but to be honest, I fail to see how > it is useful without the suppression of the notice. I mean, it's a > shorthand for isset($var)?$var:$something_else isn't it? That > presupposes that $var may not be set, but that you've accounted for that > fact, so don't want a notice about it. Obviously the isset() can only be > applied if the 'left hand side' is an lval, but I think it makes sense > to apply it whenever it is an lval. > > So a big +1 from me. > > Ben. > Its also a +1 for me, it would make the ternary operator much more useful to me e remove lots of verbose code for handling arrays. --=20 Rafael Dohms PHP Evangelist and Community Leader http://www.rafaeldohms.com.br http://www.phpsp.org.br