using global var (global settings?)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi all!

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
$ini=fopen("config.ini", "r");
  $line=fgets($ini, 100);
  if(stristr($line, 'dir1') == TRUE)
    $dir1=strstr($line, '=');
    $dir1=trim(substr($dir1, 1, 1000));
  else if(stristr($line, 'dir2') == TRUE)
    $dir2=strstr($line, '=');
    $dir2=trim(substr($dir2, 1, 1000));

Re: using global var (global settings?)

Quoted text here. Click to load it

 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.
Andy Hassall :: :: :: disk and FTP usage analysis tool

Site Timeline