RE: [PHP] Re: global scope issue
| From: | Ford, Mike [LSS] | Date: | Wed, 13 Aug 2003 15:15:07 +0000 |
| Subject: | RE: [PHP] Re: global scope issue | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-159439@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ivo Fokkema [mailto:I.F.A.C.Fokkema@LUMC.nl]
> Sent: 13 August 2003 15:45
>
> "Shawn McKenzie" <nospam@mckenzies.net> wrote in message
> news:20030813142705.28520.qmail@pb1.pair.com...
> > I'm having problems using global vars. I have read the
> docs and all of
> the
> > notes but it's not helping. Simplified example:
> >
> > /dir1/script2.php
> > <?php
> > $test = array ( 'a' => '1', 'b' => '2');
> > ?>
> >
> > /dir1/script1.php
> > <?php
> > include("/dir1/script2.php");
> > print_r($test); //works great
> > print_r($GLOBALS['test']); //does not work
> > ?>
> >
> > This is a local include so the vars should be in the global
> scope right?
> > Any help please?
> As far as I know, no defined variable is global by default.
> If you would
> really need this variable to be global, you'll need to do a
>
> global $test;
>
> to make $test global.
Absolute rubbish!! ALL variables used in the global scope are automatically
global and available in the superglobal array $GLOBALS. You're confusing
this with the issue that global variables are not automatically accessible
within functions but must be "imported" with the global statement. (And a
global statement in the gloabl scope has absolutely no effect whatsoever.)
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