Re: what is a "global"
| From: | Chris Shiflett | Date: | Fri, 07 Nov 2003 19:57:45 +0000 |
| Subject: | Re: what is a "global" | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-168899@lists.php.net to get a copy of this message | ||
--- Ryan A <ryan@coinpass.com> wrote:
> I thought i knew the useage of the "global" keyword in a function but
> after reading a pals program i am really confused, i tried
> http://php.net/global but that does not give me any
> results...searched
> the list and found some reference to global and the "scope" of the
> function but still confused.
>
> Anybody have a good link or can give me a place to read up on the
> defination with an example?
There are two scopes you need to understand in order to grok this:
1. Global
2. Function Local
Most "normal" variables are global. There are, of course, the
"superglobals" that PHP provides, but a $foo that you create is global.
The exception is when you create $foo within a function. In this case, its
scope is local to that function only. If you want it to be global instead,
you can declare it as such.
As a result of this, there are two ways that a function can manipulate
global data:
1. The variable is passed in by reference.
2. The variable is declared to be global.
Hope that helps.
Chris
=====
My Blog
http://shiflett.org/
HTTP Developer's Handbook
http://httphandbook.org/
RAMP Training Courses
http://www.nyphp.org/ramp