Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51853 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34652 invoked from network); 9 Apr 2011 23:05:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Apr 2011 23:05:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=keisial@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=keisial@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: keisial@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:49703] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/13-11380-C26E0AD4 for ; Sat, 09 Apr 2011 19:05:17 -0400 Received: by wwd20 with SMTP id 20so5508587wwd.11 for ; Sat, 09 Apr 2011 16:05:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=RZ0JN+kSIVSn53ECtR7Qut8cl+hm7YQdsBjuH34cLYU=; b=FLhqlKZN1sMw7Pf0AboZ4aArciZ8Z9rxaulVLlhH5xjUTh7JEE2dArQj01G90GJ5dm db06xPlP89dB3zr176vUaTWm6xFbt7vDEYzbujkGDeI52mq5OdlQHU9lh6bShH1sqy88 kl/8d7P7XgLnRta3J/NaCpQJN7bYXm+QPJqRU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=F3bH6JkGyoQaRhp5VjNGdYUOcLFi1Bvlj0y5sbmZYeBCDpGUDK185yLKASFkf/of1s MBzDu8wwkpWWtx8Sd5opPIBrkmAebEAgGrgZrmDU300VWwJ9EzYlBrngSNxilg+IiJVR 6zUuEFIYS0eLrIg9GhxCJigLUE9Hz9dZjv5As= Received: by 10.227.200.73 with SMTP id ev9mr3845557wbb.207.1302390314147; Sat, 09 Apr 2011 16:05:14 -0700 (PDT) Received: from [192.168.1.26] (228.Red-88-13-202.dynamicIP.rima-tde.net [88.13.202.228]) by mx.google.com with ESMTPS id o23sm2500809wbc.27.2011.04.09.16.05.08 (version=SSLv3 cipher=OTHER); Sat, 09 Apr 2011 16:05:12 -0700 (PDT) Message-ID: <4DA0E71C.9030008@gmail.com> Date: Sun, 10 Apr 2011 01:09:16 +0200 User-Agent: Thunderbird MIME-Version: 1.0 To: Sanford Whiteman , PHP Developers Mailing List 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> <718216446.20110408143441@cypressintegrated.com> In-Reply-To: <718216446.20110408143441@cypressintegrated.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: keisial@gmail.com ("=?ISO-8859-1?Q?=C1ngel_Gonz=E1lez?=") Sanford Whiteman wrote: > Same here. > > Here's my take: > > [1] I don't like ?? / ? because it is disjunctive with === / ==.. The > extra equals sign strengthens equality comparison, while the extra > question mark essentially _weakens_ the ternary operator (making it > more forgiving). (Sure, a case could be made that an "extra" duplicate > operator has no inherent meaning overall, but these two operators seem > to be in a similar domain.) I disagree. They both reinforce the operator. The = character means equivalence. == means that it is equal, === means that it is very very equal. The ? character means uncertainity, doubt. A single ? in a ternary operator means a question (if() construct). A ?? would not only mean is this true? but also does it even exists? It also looks strange to my code parser (looks like a wtf comment) but I'd probably adapt to that new operator easily. > [4] Strange idea: what about treating the variable as defined after > you test it with the special operator, even if you don't specifically > assign it a value? > > So: > > $varor2 = $var1 @?: 2 // $varor2==2, no warning because special > ternary is used > > $varor3 = $var1 ?: 3 // $varor3=3, but no warning because $var1 has > been implicitly defined in special expression This looks like a source for all kind of side-effects to me. I'm not even convinced that testing for raw variables would be useful. I think the usecase is for testing arrays. > [5] Sort of the opposite of [4] and continuing the question of [3], > what about only letting a variable be special-op-checked once before > throwing a warning. So you can suppress (or not throw) the undefined > warning once, but it is assumed that you will define the variable in > that statement. So this would discourage the continuous use of the > same undef var throughout code (which seems like a code smell), while > allowing for the real case that you're using the special-op to filter > $_REQUEST or whatever -- one time. Tests shouldn't have side effects. Allowing the special-op one time, means that the addition of a check in one place will start spewing in a completely different place of the codebase. The way of forcing the users to set the undefined variable in one check is not keeping a track if they have used a magic operation to check it and didn't set it after that, but defining a set-value-if-unset operator. A syntax like ?= looks like a set-if-set, so perhaps it would be more appropiate using !?= > I haven't really thought about the edges, but thought I'd put those > out there. Thanks for sharing!