Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- using global var (global settings?)
June 19, 2006, 4:56 pm
rate this thread
I have an app which reads from certain servers, but I'd like to have
them in am ini-file.
I made this up, but I need those vars to be visible in functions
too.... how do I do that?
// default ini values
// read in settings
if(stristr($line, 'dir1') == TRUE)
$dir1=trim(substr($dir1, 1, 1000));
else if(stristr($line, 'dir2') == TRUE)
$dir2=trim(substr($dir2, 1, 1000));
Re: using global var (global settings?)
Various options, some of which are:
(1) Access the configuration values through functions instead of globals.
(2) Define them as constants; they're always in scope.
(3) Use the "global" statement in the function.
(4) Reference the variables through $GLOBALS.
(5) It sounds like you want to register your own superglobals - this is not
trivial; runkit can do it, but that's fairly magic and unlikely to be installed
on most servers. http://www.php.net/manual/en/runkit.sandbox.php
Andy Hassall :: email@example.com :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool