Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51843 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71339 invoked from network); 8 Apr 2011 15:54:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2011 15:54:38 -0000 Authentication-Results: pb1.pair.com header.from=mjpelmear@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=mjpelmear@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mjpelmear@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-iw0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:62883] helo=mail-iw0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/D0-65418-DBF2F9D4 for ; Fri, 08 Apr 2011 11:54:37 -0400 Received: by iwn3 with SMTP id 3so4404314iwn.29 for ; Fri, 08 Apr 2011 08:54:34 -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:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=XWYCiukt+YgumtMPEx6ZnIENFpOVFFhD+tHKcwJUhXI=; b=BzcPSIA9ZLYDIXuFPiTD/NxDfaeGZFv6g/3mPhkdkmjj3YZG6NCJiJyf+VOul7pcsl 56aq4z0XAdNdLBNPf4lZacbVoiVkAuYy0lgmYKhtaz/VKNDEohiDceZrjXBrkCMJZC61 H6IPXpuEJ6EAQNHs2V05T3rg1IZLiUl1gafSY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=wdB8imuYo7fbZ61qwJdSzAvfnvLAd44wL5eYO3UUxIivVnKdGaeWuZiMhjgRGXIxQB a9hFcFMsMIIYhUhtJjCzCZYuuWmIRMqESWYFFa/R+j7CuzU00bMoSol20i/3C3K09Kcz AVXUlYuz7lhdXKWxI+gen0qXySs5b6zAewO8E= MIME-Version: 1.0 Received: by 10.42.229.195 with SMTP id jj3mr3657912icb.231.1302278073670; Fri, 08 Apr 2011 08:54:33 -0700 (PDT) Received: by 10.42.172.65 with HTTP; Fri, 8 Apr 2011 08:54:33 -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 11:54:33 -0400 Message-ID: To: internals@lists.php.net 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: mjpelmear@gmail.com (Matt Pelmear) Hello all, First post here; been watching for a while though. IMHO: 1) Implicit isset() checks in ?: would be bad. This would not "silently improve not-so-well written code"; In fact it would make not-so-well written code more difficult to debug. I can't count the number of times I've run across components that are acting oddly because somebody wrote them to ignore the fact that they're not receiving some required parameter. At least with the current functionality of ?: we get a warning. If the collective decision were to implement this, could it at least have a setting to force it to function how it does currently? 2) A shorthand assignment operator would be handy. I like the suggestion of= ??=3D where: $var ??=3D $default; is shorthand for if( !isset($var) ) $var =3D $default; Or, maybe similar to C# $var =3D $var ?? $default; (Correct me if I'm using this syntax incorrectly) This would provide a clean way to set defaults for unset vars but would make it easy to find blocks of code that are using unset vars with the ternary operator. -Matt On Fri, Apr 8, 2011 at 10:45 AM, Martin Scotta wro= te: > I just feels that !empty($arr['key']) or isset($arr['key']) do not expres= s > the real meaning, instead I would choose to write array_key_exists('key', > $arr). It may be slower but it clearly express what I meant. > > Regarding the operators, I believe they will do more harm than good. > To check if a variable was already defined is a bad programing habit, the= se > operators will encourage that kind of things > > In the other hand, the isset check inside the condition ?: would silently > improve not-so-well written code, and could be a good feature for the lan= g. > > =A0Martin Scotta