Php error on isset() function?

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
User avatar
Sascha Speidel
Forum Newbie
Posts: 1
Joined: Sat Jan 04, 2003 10:15 am
Location: Germany
Contact:

Php error on isset() function?

Post 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!
User avatar
Elmseeker
Forum Contributor
Posts: 132
Joined: Sun Dec 22, 2002 5:48 am
Location: Worcester, MA

Post 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...
laserlight
Forum Commoner
Posts: 28
Joined: Wed Jan 01, 2003 6:41 am

Post 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
Post Reply