Re: Scope issue
| From: | Richard Lynch | Date: | Mon, 20 Dec 2004 17:34:39 +0000 |
| Subject: | Re: Scope issue | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204730@lists.php.net to get a copy of this message | ||
GH wrote:
> Hi I am having an issue with I think it is the scope of variables:
>
> I have a file that I am including which has the following"
>
> <?php
> // +----------------------------------------------------------------------
> // | PHP Source
> // +----------------------------------------------------------------------
> //
>
> echo "got language.php<br />";
>
> global $langauge;
> $language['project_name'] = "P.L.I.M.S";
> $language['sub_project_name'] = "DCR CC";
> ?>
>
> In my main file, I am attempting to from with in a function call
> $language['project_name'] and i am failing... can you offer any
> advice?
Unless you are *inside* of a function definition, 'global' makes no sense
whatsoever in PHP.
Get rid of it unless you are inside function body.
But in your main script *DO* put:
global $language;
inside of your function body -- That's where you need it to be.
You may also want to consider passing $language in as an argument to your
function.
Or, if it *MUST* be a global variable, use $LANGUAGE so that it stands out
in the rest of your script.
--
Like Music?
http://l-i-e.com/artists.htm