RE: [PHP] $GLOBALS problem
| From: | Ford, Mike [LSS] | Date: | Tue, 06 Aug 2002 15:52:00 +0000 |
| Subject: | RE: [PHP] $GLOBALS problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111391@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Andy Tawse [mailto:andy.t@newmediacollective.com]
> Sent: 06 August 2002 14:17
>
> I'm having a very strange problem involving the $GLOBALS
> array. I have a global variable defined called
> $journal_month and I've been trying to access it from inside
> a function like so:
>
> $months = $GLOBALS["journal_month"];
>
> but I was getting an 'undefined index' error. The variable
> dump confirmed that PHP didnt think there was a global
> variable called journal_month. I have used $GLOBALS countless
> other times in the
> script with no problems and have actually been able to refer
> to $GLOBALS["journal_month"] from a different function. So I tried:
>
> global $journal_month;
>
> and it worked!?
>
> I didnt think there was any difference between the $GLOBALs
> array and using the global statement.
Well, only in that the global statement will "create" the variable if it
doesn't exist, but $GLOBALS[] will only access a pre-existing variable -- so
it looks like the global $journal_month doesn't actually exist yet at the
point you're referring to it, no matter how much you think it does!
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211