Page 1 of 1

Notice: How to clean undefined variables?

Posted: Thu Sep 14, 2006 3:09 am
by bob_the _builder
Hi,

How do u clear errors like:

Code: Select all

if($photos_uploaded['size'][$counter] > 0)
{
	if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
{
	echo 'File '.($counter+1).' is not a photo!<br />';
When its false I get error: Notice: Undefined offset:

and

Code: Select all

if($_GET['page'] == NULL) { 
    	$page = 1; 
}else{ 
    	$page = $_GET['page']; 
}
gives error: Notice: Undefined index

when get page is not null

?

Thanks

Posted: Thu Sep 14, 2006 3:16 am
by Weirdan

Posted: Thu Sep 14, 2006 3:37 am
by bob_the _builder
Hi,

I guess you mean change it to:

Code: Select all

if (isset($_GET['page'])) {
		$page = $_GET['page'];
}else{
		$page = 1; 
}
What about code like:

Code: Select all

if($photos_uploaded['size'][$counter] > 0)
Your not really looking for isset?


Thanks

Posted: Thu Sep 14, 2006 6:18 am
by volka
But you can first check the existence and then perform the comparison

Code: Select all

if( isset($photos_uploaded['size'][$counter]) && $photos_uploaded['size'][$counter]>0 )
for this to work without warnings it doesn't matter wether $photos_uploaded does not exist or has no element size or [$counter]. It even works if $photos_uploaded is an integer (not an array). But $counter has to exist or you will get a warning.

Posted: Thu Sep 14, 2006 2:50 pm
by bob_the _builder
Hi,

I tried that before I posted back, got an error:

Parse error: parse error, unexpected '>', expecting ',' or ')'


Thanks

Posted: Thu Sep 14, 2006 3:43 pm
by volka
Check your code again.
No syntax error in

Code: Select all

<?php
$counter = 0;
if( isset($photos_uploaded['size'][$counter]) && $photos_uploaded['size'][$counter]>0 )
{
	exit();
}
?>