Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75259 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8528 invoked from network); 5 Jul 2014 07:42:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2014 07:42:44 -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.220.178 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.220.178 mail-vc0-f178.google.com Received: from [209.85.220.178] ([209.85.220.178:42371] helo=mail-vc0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/90-33346-47CA7B35 for ; Sat, 05 Jul 2014 03:42:44 -0400 Received: by mail-vc0-f178.google.com with SMTP id ij19so2204092vcb.23 for ; Sat, 05 Jul 2014 00:42:42 -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=PFiLhfP+2XO8k4227RlM23n6HvC8YAfSWIFHwctskiM=; b=rSpBCVIaq0Wiot8gR+H7/rXaUSlmAPeM+QhKlvQx8wK9kB2IxqvyOd2t4Rz/8VJML/ 5vClf5SfIAp2zB/4Atwd3yO0DHtxMpA0gWBXlCw/gsnQGyrKgJWtAUFP8XZgq7aja4Bt aZo3NgRisHcsDrOccE0JJS4v3xkY4vKnCZ8j+oaNFiaoGchlm+rYE7GIQSfbE+KcnNV9 qxXJfs1I0fbZ8TUTWV9z1wAMB81kX20AX2OXblpX6N1+Qb4GMUIBte3JYa4Cvob6z3AF nWMcDsieWOO0SmSfrG9KuiJhOJiBR2KtbGNHhhCOXszID2VbQtzlk13Xvr3ymQ8IBJyn p1iA== MIME-Version: 1.0 X-Received: by 10.58.150.1 with SMTP id ue1mr13668707veb.11.1404546162052; Sat, 05 Jul 2014 00:42:42 -0700 (PDT) Received: by 10.58.132.71 with HTTP; Sat, 5 Jul 2014 00:42:41 -0700 (PDT) In-Reply-To: References: <002b01cf9784$4c1fe670$e45fb350$@tutteli.ch> Date: Sat, 5 Jul 2014 15:42:41 +0800 Message-ID: To: Kris Craig Cc: Xen , Levi Morrison , internals Content-Type: multipart/alternative; boundary=047d7b604e120f528f04fd6d6392 Subject: Re: [PHP-DEV] not_null function From: tjerk.meesters@gmail.com (Tjerk Meesters) --047d7b604e120f528f04fd6d6392 Content-Type: text/plain; charset=UTF-8 On Sat, Jul 5, 2014 at 3:39 PM, Tjerk Meesters wrote: > > > > 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 ;-) > Obviously spoke to soon ... what I've written there is basically an ugly `!isset($var)`. Sorry for the extra noise. > >> >> 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 > -- -- Tjerk --047d7b604e120f528f04fd6d6392--