using global var (global settings?)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sonnich

    #1

    using global var (global settings?)

    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?

    BR
    Sonnich

    // default ini values
    $dir1="\\\\serv er1\\finance";
    $dir2="\\\\serv er2\\design\\";
    // read in settings
    $ini=fopen("con fig.ini", "r");
    while(!feof($in i))
    {
    $line=fgets($in i, 100);
    if(stristr($lin e, 'dir1') == TRUE)
    {
    $dir1=strstr($l ine, '=');
    $dir1=trim(subs tr($dir1, 1, 1000));
    }
    else if(stristr($lin e, 'dir2') == TRUE)
    {
    $dir2=strstr($l ine, '=');
    $dir2=trim(subs tr($dir2, 1, 1000));
    }
    }
    fclose($ini);

  • Andy Hassall

    #2
    Re: using global var (global settings?)

    On 19 Jun 2006 09:56:17 -0700, "Sonnich" <sonnich.jensen @elektrobit.com > wrote:
    [color=blue]
    >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?[/color]

    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 :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    Working...