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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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> |