using one file to control variables

Discussion in 'PHP' started by mz906, Jun 30, 2008.

  1. #1
    is it good practice to use one file to control all global variables in php?

    a few requirements:
    variables would need to go in and out of functions
    variables would dynamically change
    variables will sometimes be assigned as arrays
    can't use the following syntax $GLOBAL[variable_name_here]

    whats the best way to achieve this?

    for example:
    var.inc contains a list of variables
    func.php contains a list of functions which requires variables from the .inc file
    my-about-page.php contains variables ONLY, so for example:

    in the my-about-page.php:
    <div id="menu">
    <?php print $menu; ?> <!--- this variable would get the function that builds the menu and that function would get the menu links from a array in the var.inc file --->
    </div>

    how can this be done? I've manged to achieve this using calls to the functions and $GLOBALS
     
    mz906, Jun 30, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    just put include once statement in all php files where u want to use the functions and variables

    Or just make a header file which is included on all pages and include func and var file in that

    Regards

    alex
     
    kmap, Jun 30, 2008 IP