Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51852 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18627 invoked from network); 9 Apr 2011 19:20:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Apr 2011 19:20:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=dante@lorenso.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dante@lorenso.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lorenso.com from 209.85.213.42 cause and error) X-PHP-List-Original-Sender: dante@lorenso.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:48367] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/01-11380-A61B0AD4 for ; Sat, 09 Apr 2011 15:20:11 -0400 Received: by ywh1 with SMTP id 1so2159526ywh.29 for ; Sat, 09 Apr 2011 12:20:06 -0700 (PDT) Received: by 10.101.5.13 with SMTP id h13mr2468036ani.42.1302376806586; Sat, 09 Apr 2011 12:20:06 -0700 (PDT) Received: from Dante-Lorensos-MacBook-Pro.local (99-147-138-4.lightspeed.allntx.sbcglobal.net [99.147.138.4]) by mx.google.com with ESMTPS id w39sm4251473ana.39.2011.04.09.12.20.04 (version=SSLv3 cipher=OTHER); Sat, 09 Apr 2011 12:20:05 -0700 (PDT) Message-ID: <4DA0B163.6090405@lorenso.com> Date: Sat, 09 Apr 2011 14:20:03 -0500 Reply-To: dante@lorenso.com User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 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> <20110407223526.GJ7113@crousti> In-Reply-To: <20110407223526.GJ7113@crousti> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: dante@lorenso.com ("D. Dante Lorenso") On 4/7/11 5:35 PM, Etienne Kneuss wrote: > On Apr 07 18:03:48, Rasmus Lerdorf wrote: >> On 4/7/11 5:59 PM, Matthew Weier O'Phinney wrote: >>> It may change the semantics as they stand, but I'd argue that the >>> _expectation_ from the shorthand ternary is to shorten code that >>> currently uses isset(). As it is, I have almost no use for it at this >>> point, as I end up needing to do: >>> >>> $value = isset($a[$key]) ? $a[$key] : 'Not set'; >>> >>> which is exactly the situation I had before it was introduced. >> >> Not sure why you would have that expectation. The long ternary doesn't >> do that, and there is nothing about the short ternary that changes that. >> There was talk of a new ifsetor type of operator to have those semantics >> but never any talk of changing existing semantics. > > Well it could (and I believe that was the intention) call !empty instead > of isset, that way the semantics would not be changed, appart from the > lack of error for undefined variables. Since I see the beast has risen from the dead, I'd like to chime in again for my proposal to have a "function" called "filled". It is the opposite of empty() and takes variable number of arguments. The first non-empty value is returned. example: $x = filled($myarray['badkey'], $varundef, $obj->nosuch, $default); This *must* be created in the Zend engine because userland can not catch the unset keys and variables. Again, "filled()" would be the opposite of empty() and we'd need some other function similar to be the opposite of isset() if you wanted that type of check. The proposed filled() will suit all my needs with great satisfaction :-) -- Dante ---------- D. Dante Lorenso dante@lorenso.com 972-333-4139