On Fri, Jul 4, 2014 at 2:38 PM, Xen <x...@dds.nl> 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):  ????
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

Reply via email to