On 13 Oct 2011 at 16:25, Tedd Sperling <tedd.sperl...@gmail.com> wrote: 

> So, if in your main script you have the statement:
>
> $myVar = 'test';
>
> Then the $GLOBAL['myVar'] has also been created and will hold the value of
> 'test' without any additional coding.
>
> While many of you will say "But of course, that's the way it works." I
> actually said "What?!?" You see, I seldom use globals in my scripts and this
> runs counter to my 'keep the globals to an absolute minimum' practice. So
> while I was thinking my scripts didn't have globals, it was a surprise to me
> to find out that in the background they were present anyway.
>
> So, if you want a main script variable (i.e., $myVar) to be accessed by a
> function, you can do it by stating:
>
> myFunction
>   {
>   global $myVar;
>   // and then using $myVar
>   }
>
> or
>
> myFunction
>   {
>   $myVar = $GLOBAL['myVar'] 
>   // and then using $myVar
>   }

But presumably these are not *quite* equivalent, as modifying $myVar will 
change the global in the first but not in the second.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to