Page 1 of 1

Undefined variable notice question

Posted: Thu Feb 10, 2005 4:24 pm
by mikebr
I am wondering the importance of a notice error on an undefined variable, or rather the importance of having an undefined variable, I know it get the error as I have the php.ini file set to show all errors including notice errors (I am testing locally). How important is this? is it something I should ignore by setting my ini file to not show Notices?

I remember reading that it wasn't needed to define a php veriable but if that is the case then why would this error exit?

The notce error:

Notice: Undefined variable: at in /Users/mikebr/Sites/_CONFIGURE.php on line 68

Thanks

Posted: Thu Feb 10, 2005 4:44 pm
by d3ad1ysp0rk
Could you maybe show us the code?

Adding to a variable like so:

Code: Select all

<?php
$uvar .= "new text.<br />";
?>
Isn't a really big deal, as long as it works.

However, doing something like this:

Code: Select all

<?php
mysql_query($uvar);
?>
IS, since it would mean the query wouldn't execute due to the variable not being there.

I'd always suggest making sure you know where it's coming from and that it's initialized.

Posted: Thu Feb 10, 2005 5:27 pm
by feyd
for professional work, having no notices/warnings/errors in code is good. If it's for personal, it only matters as far as you care.

Posted: Fri Feb 11, 2005 7:28 am
by mikebr
OK, I am testing locally but it would move to production eventually.

I wouldn't be using the variable as part of a query. What is happening is that I have code at the top of my page such as:

Code: Select all

<?php
if ($userAlert) &#123;
print "$userAlert";
&#125;
?>
If there is no user alert then I get the Undefined notice, but the user alert would only exist if there was a user alert, normally there wouldn't be.

Thanks

Posted: Fri Feb 11, 2005 7:33 am
by djot
-

Code: Select all

<?php 
if (isset($userAlert)) &#123; 
print "$userAlert"; 
&#125; 
?>
djot
-

Posted: Fri Feb 11, 2005 1:29 pm
by mikebr
OK, this seems to do the trick.

Thank you