Undefined variable notice question

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
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Undefined variable notice question

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post 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
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-

Code: Select all

<?php 
if (isset($userAlert)) &#123; 
print "$userAlert"; 
&#125; 
?>
djot
-
mikebr
Forum Contributor
Posts: 243
Joined: Sat Sep 28, 2002 7:05 am

Post by mikebr »

OK, this seems to do the trick.

Thank you
Post Reply