Page 1 of 1

Php error on isset() function?

Posted: Sat Jan 04, 2003 10:15 am
by Sascha Speidel
Hi @all!

I have a question! When I use the isset() function in a PHP script, for example like that:

<?
if(!isset($var)){
echo "Hello World!";
}
else{
echo "ERROR!";
}
?>

and later I look in my error.log file and have got an error:

[Sat Jan 4 16:27:03 2003] [error] PHP Notice: Undefined variable: var in /usr/home/fsascha/htdocs/script.php on line 2

I know the variable was not declared previously! Is this error normal?

Thanks for helping!

Posted: Sat Jan 04, 2003 11:05 am
by Elmseeker
Yes, it's normal, it's not really an error, it is more of a warning. It is just there to let you know that the variable was previously undeclared. It shouldn't actually cause any trouble for you but if you want to stop those lines from appearing in your logs simply put:

Code: Select all

$var = '';
In the code before it's used...of course if you're getting the variable from another source such as the previous page this won't work, then you would have to retrieve it from the $_POST, $_GET, etc...depending on where it is stored. and use that value instead of '' to initialize it...

Posted: Sat Jan 04, 2003 11:10 am
by laserlight
hmm, why should it be normal for isset()?

http://www.php.net/manual/en/function.isset.php

the user notes seem to indicate that there was no error notice, at least in 2000