Page 1 of 1
Notice: Undefined variable error
Posted: Tue Feb 01, 2005 1:53 pm
by ljCharlie
The PHP pages used to work under PHP 4.0.6 but now that we moved to PHP version 5.0.3, I'm getting the error "Notice: Undefined variable" on almost all of my PHP pages. Will anyone tell me what might be the problem here?
ljCharlie
Posted: Tue Feb 01, 2005 1:55 pm
by magicrobotmonkey
its a matter of different error level reporting. Its caused by using variables without intializing them first. It can be fixed by changing you error reporting level or by going back through your code and ensuring that all variables are intialized properly.
Posted: Tue Feb 01, 2005 1:57 pm
by ljCharlie
Okay, so in version 5, PHP requires that I must initilalized all my variables first, correct? If so, how do I initialized in PHP then?
Many thanks for your response.
ljCharlie
Posted: Tue Feb 01, 2005 2:21 pm
by magicrobotmonkey
its the same in all versions of php, the difference is that when you installed 5 it had a higher level of error reporting.
To initialize variables, you just set it equal to something. You will get the notice if you do something like $string .= "blah"; without first doing $string = "Something";
Posted: Tue Feb 01, 2005 2:39 pm
by josh
In php.ini set error reporting to E_ALL & ~E_NOTICE
look for a line that says:
error_reporting = E_ALL
and just make it
error_reporting = E_ALL & ~E_NOTICE
Posted: Tue Feb 01, 2005 2:44 pm
by ljCharlie
I see what you're saying now. Thanks! However, I have one other question. Here are some codes I have in one PHP page.
Code: Select all
echo '<form name="frmScholarship" method="post" action="'.$self.'">';
echo '<select name="sltScholarship" id="sltScholarship" onChange="frmScholarship.submit()">';
How do I test if the variable
sltScholarship is initilized or not? I'm having an error on this
sltScholarship variable when coming from a differnt page to this particular page. Now, once I'm in this page I no longer receive this error because the page is submitting to self.
ljCharlie
Posted: Tue Feb 01, 2005 2:57 pm
by ljCharlie
Many thanks for all your help. I got it working now.
ljCharlie
Posted: Tue Feb 01, 2005 6:23 pm
by feyd
hiding malformed code by changing error reporting isn't a good idea..