Re: Globalness of variables? Functions & subs
| From: | Rasmus Lerdorf | Date: | Tue, 24 Apr 2001 22:12:02 +0000 |
| Subject: | Re: Globalness of variables? Functions & subs | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-50199@lists.php.net to get a copy of this message | ||
> I noticed that you have to use keyword "global" in front of globla
> var.- (one declared at the top of a script outside any functions ) in
> order to access it inside a function. So merely designating a var.
> global is a little more involved than say Perl or other languages. You
> actually have to tell PHP that the function is global.
Correct. That is to avoid nasty side-effect bugs where global variables
override local variables in functions. In PHP you need to declare which
global variables you intend to use inside a function. Let's just say I
had a bad experience once related to this and that is why this is so.
You can use $GLOBALS['var_name'] in your function as a workaround if you
don't like declaring which globals you intend to use.
> I see functions , are there subroutine calls. I guess not. A function
> acts as a sub when it returns no value . A sub that returns a value is
> a function.
I see no point in this distinction. And no, PHP just has functions. And
a function doesn't need to return anything.
-Rasmus