Re: not_null function

From: Date: Thu, 03 Jul 2014 11:40:19 +0000
Subject: Re: not_null function
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-75222@lists.php.net to get a copy of this message
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.

« previous php.internals (#75222) next »