Page 1 of 1
[SOLVED] isset ignores mysql null
Posted: Thu Apr 28, 2005 8:49 pm
by The Monkey
PHP Manual wrote: ... isset() will return FALSE if testing a variable that has been set to NULL ...
In my database wrapper, I have this code here:
Code: Select all
function field($key)
{
if ( isset($this->rowї$key]) )
{
return $this->rowї$key];
}
trigger_error('The specified field `' . $key . '` does not exist.', E_USER_ERROR);
return false;
}
However, if I query a mysql entry and it has a field set to null, then an error is logged and - blam - I don't get my acceptable return value of NULL. I like my error logging mechanism the way it is, though... it I have a typo and ask for a field like 'naem' instead of 'name', I instantly know the problem.
So how do I determine if a variable is actually SET, with null being an acceptable value?
Posted: Thu Apr 28, 2005 8:51 pm
by SBro
Could you not do the following?
Code: Select all
function field($key)
{
if ( isset($this->row[$key]) || is_null($this->row[$key]) )
{
return $this->row[$key];
}
...
Posted: Thu Apr 28, 2005 8:57 pm
by The Monkey
Yes, I can.

I'm sorry, long day.

Thank you!