check if var initialized?

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
Dark_Raider
Forum Newbie
Posts: 4
Joined: Mon May 12, 2003 1:16 pm

check if var initialized?

Post by Dark_Raider »

how do i check if a variable is initialized? i have an array and keep getting uninitialized string offset error. isset, is_null, anything else i can think of, doesnt work. please help.
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

tried empty()?

tried if($var=='')?
Dark_Raider
Forum Newbie
Posts: 4
Joined: Mon May 12, 2003 1:16 pm

Post by Dark_Raider »

yeah ive tried both (oh and i dont wanna use the @ to supress the error)
Dark_Raider
Forum Newbie
Posts: 4
Joined: Mon May 12, 2003 1:16 pm

Post by Dark_Raider »

i think that in $proj["est"][$i] all of the values for $i are set but they just arent initialized. in other words the array elements were created but nothing was ever put into them.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

there are three levels you might check.

Code: Select all

if ( isset($proj) && is_array($proj) )
{
	if ( isset($proj["est"]) && is_array($proj["est"]) )
	{
		if ( isset($proj["est"][$i]) )
			echo $proj["est"][$i];
	}
}
Post Reply