[SOLVED] isset ignores mysql null

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

[SOLVED] isset ignores mysql null

Post 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?
Last edited by The Monkey on Thu Apr 28, 2005 8:57 pm, edited 1 time in total.
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post 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];
    }
    ...
The Monkey
Forum Contributor
Posts: 168
Joined: Tue Mar 09, 2004 9:05 am
Location: Arkansas, USA

Post by The Monkey »

Yes, I can. :oops: I'm sorry, long day. :P Thank you!
Post Reply