Page 1 of 1
Why am i getting so many Undefined variable notices?
Posted: Tue Jun 03, 2003 1:08 am
by Azmerod
I have about 100 or so undefined variable notices when i try to load up my index.php file. And this is even happening with other files that have been proven to work correctly. I'm running winXP with php 4.3.2 installed and apache 1.3.
Posted: Tue Jun 03, 2003 1:22 am
by delorian
Try to use something like this at the top of your script:
Code: Select all
error_reporting(E_ALL & ~E_NOTICE);
You get "undefined variable notices", probably because of that you have error_reporting directive set to E_ALL in your php.ini file. There is a part that begins with:
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Set directive error_reporting to E_ALL & ~E_NOTICE and it should work fine.

Posted: Tue Jun 03, 2003 2:29 am
by volka
but check those notices first (and let error_reporting at E_ALL on your development system)
Refering to your HTTP_USER_AGENT question I'd say you try to access Get/POSTed variables (or similar) with register_globals off.
So $formVar should be something like $_POST['formVar'] and $PHP_SELF $_SERVER['PHP_SELF']
Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+ has something to say about that as has
http://php.net/reserved.variables
Posted: Tue Jun 03, 2003 3:55 am
by twigletmac
delorian wrote:Try to use something like this at the top of your script:
Code: Select all
error_reporting(E_ALL & ~E_NOTICE);
You get "undefined variable notices", probably because of that you have error_reporting directive set to E_ALL in your php.ini file. There is a part that begins with:
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Set directive error_reporting to E_ALL & ~E_NOTICE and it should work fine.

To add a bit more to what volka said ('cause this is one thing that really irritates me), turning off notices does not fix the problem, it only hides it - PHP is still encountering them it's just not being reported to you. These kind of errors are generally incredibly easy to fix and having your error reporting turned up as high as possible will aid you in the long run. Notices can be incredibly useful when you mispell a variable name or try and do something with a variable that does not exist. I object heavily to 'turn down your error reporting' being presented as a solution to a problem - if you turn it off does it prevent parse errors.</objection>
Mac
in the long run
Posted: Tue Jun 03, 2003 12:01 pm
by owen
in the long run defining your variables will make your programm more stall and it will be easier for you to know when something has gone horribly wrong. Also there are a few parser errors that can only be found if E_ALL is set (I don't know why exactly).
Posted: Tue Jun 03, 2003 12:54 pm
by McGruff
I definitely agree with Twig here. Unset variables are vulnerable to value substitution - particularly if you have register globals on - so you definitely want to know about them.
Hunt them down in your scripts and work out why they are not being assigned a value.
If an undefined var is declared in an IF clause make sure there is an ELSE clause at the end to sweep up any cases not covered by the IF or ELSEIF statements.
Or, simple typos: "$site_name" declared somewhere then you refer to it later as "$sitename".
You could also give undefined vars a default value at the start of your scripts - null or something.
Of course this all refers to developer level error reporting: you'd want to log errors and use lots of "@"'s on a live site.