Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75257 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6988 invoked from network); 5 Jul 2014 07:39:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2014 07:39:20 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.177 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.177 mail-ve0-f177.google.com Received: from [209.85.128.177] ([209.85.128.177:62433] helo=mail-ve0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/40-33346-8ABA7B35 for ; Sat, 05 Jul 2014 03:39:20 -0400 Received: by mail-ve0-f177.google.com with SMTP id i13so2296215veh.22 for ; Sat, 05 Jul 2014 00:39:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=I4+46HEPu+kYWtPqIjbZF0O+0Ar9koYZcosW+zx84cg=; b=Jh8tjVpf/mM6iiEzRpYvm9jO2G/dqhAZ7R/dHAnREHnrtcGD3Ankr+W56TtaN4ZCx/ 9986CWZ7hq1f73I/t01jEinWzjZwcWnib/67cOgQDUgb6dIyiLdjTHtLXs2iczzmCaYt Y5yAOob33869AG9VrErPz65teWCeLisgmfpCxAisFufiG7UPcFaRQLhUP2a7+mhWvnAI EyvQJ+4f2Z4ZODm7p5USCLObGMnHW6elSsew31P9XRbXW4RpvgtInMyzpUiP3fI0o5x0 DsZpztNC1oTZK/O7rxu1vUKBN/S8VLPPdP3DSBjDiUNeQP6o62CxycctV8Ojqh4SB1PF /5cw== MIME-Version: 1.0 X-Received: by 10.52.253.131 with SMTP id aa3mr11638030vdd.25.1404545956956; Sat, 05 Jul 2014 00:39:16 -0700 (PDT) Received: by 10.58.132.71 with HTTP; Sat, 5 Jul 2014 00:39:16 -0700 (PDT) In-Reply-To: References: <002b01cf9784$4c1fe670$e45fb350$@tutteli.ch> Date: Sat, 5 Jul 2014 15:39:16 +0800 Message-ID: To: Kris Craig Cc: Xen , Levi Morrison , internals Content-Type: multipart/alternative; boundary=001a1135e9b6d5d33604fd6d5620 Subject: Re: [PHP-DEV] not_null function From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a1135e9b6d5d33604fd6d5620 Content-Type: text/plain; charset=UTF-8 On Sat, Jul 5, 2014 at 9:22 AM, Kris Craig wrote: > 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. > > 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): ???? > Yep, nothing exists for that; we have a whole bunch of `_exists()` functions, but not e.g. `variable_exists()` or even a dedicated `exists` opcode. > Variable exists and === NULL: ???? > That's simply `@$var === null` or `@is_null($var)` of course ;-) > > 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 > -- -- Tjerk --001a1135e9b6d5d33604fd6d5620--