Results 1 to 18 of 18

Thread: [Resolved] Include/Require Problem

Threaded View

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [Resolved] Include/Require Problem

    This problem has really bothered me for a long time, but I've just tried to get around it. Now it's getting to be annoying, so I'm hoping there's a solution.

    I'm having a problem including/requiring a file within a function, and still having variables it created be defined through a few more function calls. I know that probably doesn't make sense, so I trimmed down my code to the bare-minimum for an example.

    index.php is the main page, which calls a display.php (for displaying news in my program). display.php calls config.php, which simply loads configuration variables into an array.

    Code:
    index.php
    <?php
        // There would normally be some type of if structure
        // here, that's why a function is needed:
    
        main();
    
        function main() {
            require 'display.php';
    
            execute();
        }
    ?>
    
    display.php
    <?php
        require 'config.php';
    
        function execute() {
            global $CONFIG;
    
            echo 'The var: ' . $CONFIG['name'];
        }
    ?>
    
    config.php
    <?php
        // this usually loads values form a database
        $CONFIG['name'] = 'value';
    ?>
    Now, the execute() function of display.php is supposed to output a variable value, but no dice.

    My question to you is, what can I do to make this work, besides fudging around in the index.php file (since I want my users to be able to call it however they need to)?
    Last edited by The Hobo; Feb 25th, 2004 at 11:58 AM.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width