Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75280 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97984 invoked from network); 6 Jul 2014 10:48:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jul 2014 10:48:42 -0000 Authentication-Results: pb1.pair.com header.from=php@tutteli.ch; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@tutteli.ch; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain tutteli.ch designates 80.74.154.78 as permitted sender) X-PHP-List-Original-Sender: php@tutteli.ch X-Host-Fingerprint: 80.74.154.78 ns73.kreativmedia.ch Linux 2.6 Received: from [80.74.154.78] ([80.74.154.78:48781] helo=hyperion.kreativmedia.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/B1-16090-98929B35 for ; Sun, 06 Jul 2014 06:48:41 -0400 Received: (qmail 8742 invoked from network); 6 Jul 2014 12:48:38 +0200 Received: from 178.165.131.25.wireless.dyn.drei.com (HELO RoLaptop) (178.165.131.25) by ns73.kreativmedia.ch with (AES128-SHA encrypted) SMTP; 6 Jul 2014 12:48:37 +0200 To: "'Kris Craig'" , "'Xen'" Cc: "'Levi Morrison'" , "'internals'" References: <002b01cf9784$4c1fe670$e45fb350$@tutteli.ch> In-Reply-To: Date: Sun, 6 Jul 2014 12:48:33 +0200 Message-ID: <003701cf9907$d7287f50$85797df0$@tutteli.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQEXw8xSC1llRw+ZtijSr3FQoKfQBQIyjvgLAeIlKlYCNl3q0wGCMQrUA2EMrWmcqRTzsA== Content-Language: de-ch Subject: RE: [PHP-DEV] not_null function From: php@tutteli.ch ("Robert Stoll") > -----Original Message----- > From: Kris Craig [mailto:kris.craig@gmail.com] > Sent: Saturday, July 05, 2014 3:22 AM > To: Xen > Cc: Levi Morrison; internals > Subject: Re: [PHP-DEV] not_null function > > On Fri, Jul 4, 2014 at 2:38 PM, Xen wrote: > > > On Fri, 4 Jul 2014, Levi Morrison wrote: > > > > For completeness, it is available in Perl and I believe Perl had it > >> first; not completely sure though. > >> > > > > Okay, I never used Perl. > > > > > > I don't think changing isset would be beneficial, sadly. I wish it > >> only checked that a variable exists and didn't do the not null check > >> but it's used very, very widely. > >> > > > > As long as people don't have to use isset anymore to check for a not-null, > > perhaps over time this widespreadedness would become less. > > > > As soon as you can use "unless (is_null())" to check whether a variable > > exists and is not null, the need for using isset for this should greatly > > diminish... > > > > Just my perspective. I don't know what other people think, the boogieman > > of this list seems to not want to discuss anything related to this, so I > > don't know. > > > > I mean for me it means having to rethink my thinking, i.e. to get used to > > this new statement. But it would probably become very natural? > > > > I would imagine a lot of people becoming enthusiastic about an "unless" > > statement. It is also a sexy thing to introduce and it doesn't require any > > changes to existing code. > > > > Again, just my perspective. Curious what other people really think at this > > point. > > > > Regards, Bart > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > I'm not much into Perl or Ruby, either, but I agree that an unless keyword > would be a very nice thing to have. However, I'm still not sure how that > would solve the isset problem. If the variable doesn't exist, are you > saying that encapsulating it within the unless arg would prevent an > undefined variable notice from being thrown? If so, could someone > elaborate on why that is? And if not, then while I do agree it's a good > idea on its own merits, I don't think it solves the issue we're mulling > over here. > [Robert Stoll] I suggested "unless" for the initial problem -> is_null does not exists. And it would only be a substitute for "if(!())" Maybe it would be good idea to rename this thread since the topic has obviously changed by now. > Currently, this is what's available for checking a variable's status > without throwing any errors: > > Variable exists and !== NULL: isset( $var ) > Variable === NULL or doesn't exist: !isset( $var ) > Variable == NULL or doesn't exist: empty( $var ) > Variable exists and != NULL: !empty( $var ) > Variable exists (including NULL): ???? > Variable exists and === NULL: ???? > > It's those last two cases that we currently don't have any streamlined > approach for. If a variable is NULL and you use isset() on it, the return > will be FALSE. So if you were to do something like isset( $var ) && $var > === NULL, that statement will always return FALSE, even you set the > variable with $var = NULL beforehand. You'll get the same problem using > empty(). In other words, as far as I can tell, there's currently no way to > tell if a variable is set and NULL (or just set with any value including > NULL) in PHP. > > The closest thing I could find that accomplishes this is property_exists(). > That function will return TRUE even on NULL values. But as I understand > it, that function only works on properties; i.e. variables that are a part > of a class. There doesn't seem to be any option for doing this with > procedural variables. We know that setting a variable to NULL in PHP is > not the same as unsetting it because referring to it later won't throw an > undefined notice, but aside from catching that notice itself, there doesn't > seem to be any way to accomplish this. Am I missing something? I realize > it's an edge case, but it still needs to be covered. > > --Kris