Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75222 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25143 invoked from network); 3 Jul 2014 11:40:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jul 2014 11:40:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=xen@dds.nl; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=xen@dds.nl; sender-id=unknown Received-SPF: error (pb1.pair.com: domain dds.nl from 85.17.251.144 cause and error) X-PHP-List-Original-Sender: xen@dds.nl X-Host-Fingerprint: 85.17.251.144 smtp.dds.nl Linux 2.6 Received: from [85.17.251.144] ([85.17.251.144:50211] helo=montblanc.dds.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/01-47713-62145B35 for ; Thu, 03 Jul 2014 07:40:23 -0400 Received: from swan.dds.nl (swan.dds.nl [85.17.251.134]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by montblanc.dds.nl (Postfix) with ESMTPS id 6EABD6E073D; Thu, 3 Jul 2014 13:27:43 +0200 (CEST) Date: Thu, 3 Jul 2014 13:40:19 +0200 (CEST) To: Kris Craig cc: Tjerk Meesters , PHP Internals In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=UTF-8 X-Virus-Scanned: clamav-milter 0.97.8 at montblanc X-Virus-Status: Clean Subject: Re: [PHP-DEV] not_null function From: xen@dds.nl (Xen) On Thu, 3 Jul 2014, Kris Craig wrote: > I've found over the years that a lot of developers, particularly those who > specialize in languages other than PHP, use is_null() when what they really > want is empty(). > > The problem with is_null() and the === operator is that PHP will throw a > notice if the variable is not set. If you're just looking for whether a > variable is blank or not, empty() will handle that whether the variable is > set or not. Personally, I don't understand why we need is_null() at all in > its current form, since it's exactly the same as === NULL, except that it > doesn't perform as well. > > Rather than removing it, I think is_null() should be changed into a > language construct like isset() and empty(). That way, people could pass > undefined variables to is_null() without triggering notices. It'd > basically be the same as empty, except that it would only return true of > the value is exactly NULL. > > empty( $var ) is functionally equivalent to isset( $var ) && $var == NULL > is_null( $var ) should be functionally equivalent to isset( $var ) && $var > === NULL > > I think that would make a hell of a lot more sense than the way is_null() > works now. Thoughts? For PHP, empty() is congruent because PHP works with buckets that have names. Personally, I consider that incongruent with programming itself, which is why I hesitate to use empty() because to my mind it implies a container and a variable is for me not necessarily a container that has one or more elements. I guess if you can wrap your mind around that, it is fine, but I can't. (!empty()) feels a lot better to me though than (!is_null()). I would definitely prefer that over the other. But like I said in my other reply, I feel this "!empty" should get replaced with "not_null". If "!null()" were possible we'd have that but that is not an option no matter how far and hard you push it. But we are on the same track and I like that :D!. Regards, Bart Schouten / Xen.