By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,637 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,637 IT Pros & Developers. It's quick & easy.

PHP saying I have an undefined variable?

P: n/a
Hi,

I get the following error:
Notice: Undefined variable: end_while in C:\Program
Files\Apache\Apache2\htdocs\csp\inc\xmlmenu.php on line 102
This is a script that works on the server at work but it has difficulty
with me running on my home desktop. The variable, $end_while, is just a
basic variable. Is this a configuration problem where you can allow
undefined variables? Ive never had to define variables in the past.

Cheers

Burnsy

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
bi******@yahoo.co.uk wrote:
Notice: Undefined variable: end_while in C:\Program
Files\Apache\Apache2\htdocs\csp\inc\xmlmenu.php on line 102
This is a script that works on the server at work but it has difficulty
with me running on my home desktop. The variable, $end_while, is just a
basic variable. Is this a configuration problem where you can allow
undefined variables? Ive never had to define variables in the past.


See: http://php.net/error_reporting

Example 1 shows how to turn it off. _BUT_ you shouldn't do that, fix the
code instead.

Jul 17 '05 #2

P: n/a
Note that this is not an error but a notice - there's a difference. Errors
will stop execution of your script, while warnings and notices are there to
inform you of possible faulty code. Depending on your error_reporting
setting in php.ini, you may or may not see warnings and notices. Your script
has an undefined variable on your server but your server is just not telling
you, because error_reporting is set to off or warn (not all).

It is likely that you are using $end_while in a conditional statement before
you have defined it, leading to the notice. You should set it to a default
value at the beginning of your script, or before you use it.

ECRIA
http://www.ecria.com
Jul 17 '05 #3

P: n/a
If you dont want to define the variable first - you can always use a
conditional to act if it doesnt exist:
if(!isset($varname))
{
do something
}
Or to supress the notices you can set the PHP error level reporting at
runtime using:
error_reporting(E_ALL ^ E_NOTICE);
That is; if you dont have access to your PHP.ini!

Regards
- FrobinRobin

ECRIA Public Mail Buffer wrote:
Note that this is not an error but a notice - there's a difference. Errors
will stop execution of your script, while warnings and notices are there to
inform you of possible faulty code. Depending on your error_reporting
setting in php.ini, you may or may not see warnings and notices. Your script
has an undefined variable on your server but your server is just not telling
you, because error_reporting is set to off or warn (not all).

It is likely that you are using $end_while in a conditional statement before
you have defined it, leading to the notice. You should set it to a default
value at the beginning of your script, or before you use it.

ECRIA
http://www.ecria.com


Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.