Global Variables

This is a discussion on Global Variables within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hey it's me again, I am wondering if there is a (secure) way to create a variable that is ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-30-2004
Aaron Murray
 
Posts: n/a
Default Global Variables

Hey it's me again,

I am wondering if there is a (secure) way to create a variable that is
global. For example, I have an include file right now that defines a number
of arrays for site configuration - eg:

$FilePath = array ("Logs" => "MyLog/", "Templates" => "MyTemplate/");

Lexically speaking, this is fine from the main script. The scope of the
variable resides within the main script. However when I go into a function
it is no longer in scope, obviously. I can always pass the information
through an arguement ie

WriteLog($FilePath['Logs'], 'error.log', $ErrorNum, $ErrorDetails);

This works fine, however, it is a little cumbersome. I know avoiding
use of global variables is good programming, but in this case it would make
life much easier if I could define a few global variables. Can someone
please tell me the best way to do this?

Thanks
/Aaron


Reply With Quote
  #2 (permalink)  
Old 01-30-2004
Andy Hassall
 
Posts: n/a
Default Re: Global Variables

On Fri, 30 Jan 2004 20:00:03 GMT, "Aaron Murray" <__nospam__@hotmail@.com>
wrote:

> I am wondering if there is a (secure) way to create a variable that is
>global. For example, I have an include file right now that defines a number
>of arrays for site configuration - eg:
>
> $FilePath = array ("Logs" => "MyLog/", "Templates" => "MyTemplate/");
>
> Lexically speaking, this is fine from the main script. The scope of the
>variable resides within the main script. However when I go into a function
>it is no longer in scope, obviously. I can always pass the information
>through an arguement ie
>
> WriteLog($FilePath['Logs'], 'error.log', $ErrorNum, $ErrorDetails);
>
> This works fine, however, it is a little cumbersome. I know avoiding
>use of global variables is good programming, but in this case it would make
>life much easier if I could define a few global variables. Can someone
>please tell me the best way to do this?


(a) The 'global $FilePath' statement to bring the global into scope.
(b) The $_GLOBALS array, visible from all scopes.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk> / <http://www.andyhsoftware.co.uk/space>
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0