Before anyone says anything, I've read through this whole thread, and another couple about poassing Post & GET variables... however no-one has ever mentioned what you do if you have an undefined variable...
For example:
I've created what I call modules, and depending on the _Post variable $command it includes a specific file, which does an action. However, if you are opening the "page" for the first time, the command varilable is purposefully blank.
This worked under the previous php versions, however with register globals in the new setting, is says that the index is undefined.
Is there a way around this? Please!
Undefined variable error
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
[Moved this from: viewtopic.php?t=511]
Undefined variable errors are caused when you try and access a variable that has not been set, for example if you had:
and $_GET['action'] was not set you would get a notice about an undefined variable.
To avoid these notices, start using empty() and isset(), so you could change the above to:
or if you had
you could change it to
of course if you post some of the code that you're having problems with I could give a more specific example.
BTW, the reason you didn't get the error (notice) in your previous version of PHP was because error reporting was set lower - some people will tell you that the solution to getting rid of errors like this you should just lower the error reporting level but this isn't a solution, the error still occurs but it's just not reported.
Mac
Undefined variable errors are caused when you try and access a variable that has not been set, for example if you had:
Code: Select all
if ($_GET['action'] == 'go') {To avoid these notices, start using empty() and isset(), so you could change the above to:
Code: Select all
if (!empty($_GET['action']) && $_GET['action'] == 'go') {Code: Select all
if ($_GET['action']) {Code: Select all
if (empty(!$_GET['action'])) {BTW, the reason you didn't get the error (notice) in your previous version of PHP was because error reporting was set lower - some people will tell you that the solution to getting rid of errors like this you should just lower the error reporting level but this isn't a solution, the error still occurs but it's just not reported.
Mac