# Isset question

- Thread: https://externals.io/message/14020
- Original archive: https://news-web.php.net/php.internals/14020
- Started by Jason Garber on 2004-12-08T07:39:30+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #14020 — Jason Garber — 2004-12-08T07:39:30+00:00

URL: https://externals.io/message/14020#14020

Hello internals,

  If anyone has a moment to answer this, it'd be appreciated...

  --
  isset($x);  => false
  is_null($x) => Notice: undefined variable $x

  --
  $x = null;
  isset($x);  => false
  is_null($x) => true

  The question is *why* does isset() report false on a variable that
  is set to NULL?  Is there any way to tell if a variable isset and
  is_null without generating an error?

  It doesn't seem that this behavior is consistent with the meaning of
  isset(), or the errors that are generated when a variable is not set.

  
  Thanks.
  
-- 
Best regards,
 Jason Garber                      mailto:jason@ionzoft.com
 IonZoft, Inc.

---

## #14021 — Richard Mann — 2004-12-08T09:06:37+00:00

URL: https://externals.io/message/14020#14021 · In reply to: #14020

I thought if you used something like:

if ((isset($x)) && is_null($)) {
...
}

it would work as it would hit the first condition and drop out if it is not
set before using it in the second.

I might be wrong. ;-)

---

## #14025 — Todd Ruth — 2004-12-08T16:24:01+00:00

URL: https://externals.io/message/14020#14025 · In reply to: #14020

Here is one reason: $x = @$y[3];
What should isset($x) return if $y doesn't have an
index 3?

If php had distinct concepts of "undefined" (perhaps
this would be a software level undefined value) and
"null" (perhaps this would be a built-in user level 
undefined value), things would work very differently.  
In the example above $x would be "undefined" as would 
any unused variable, and there would be a way to check
whether a variable was undefined.  If you never use
null as a handy way to indicate user level undefinedness,
you won't have any problem with the lack of distinction.
"null" _is_ php's "undefined".  As such, it makes sense
for $x to be null and isset to return false.  If you 
try to use "null" to indicate, for example, that the user 
hasn't yet responded to a question (or that a value from a
database was "null"), you will likely have moments of 
frustration.

That sounded biased, so I have to point out that
making the aforementioned distinction is not a
panacea.  It assumes only two layers: software and
user.  Even if the distinction were made, if the software
had 2 or more layers, you could still end up with
the same issues.  There would need to be conversions
between undefined and null at the layer boundaries.

I'm typically just a lurker here and have only
contributed a few lines of code (and those didn't
even make it in), so these are just the observations
of a user that has played with the internals a bit.

- Todd


> Hello internals,
> 
>   If anyone has a moment to answer this, it'd be appreciated...
> 
>   --
>   isset($x);  => false
>   is_null($x) => Notice: undefined variable $x
> 
>   --
>   $x = null;
>   isset($x);  => false
>   is_null($x) => true
> 
>   The question is *why* does isset() report false on a variable that
>   is set to NULL?  Is there any way to tell if a variable isset and
>   is_null without generating an error?
> 
>   It doesn't seem that this behavior is consistent with the meaning of
>   isset(), or the errors that are generated when a variable is not set.
> 
>   
>   Thanks.
>   
> -- 
> Best regards,
>  Jason Garber                      mailto:jason@ionzoft.com
>  IonZoft, Inc.
