|
-
Feb 22nd, 2004, 02:15 PM
#1
Thread Starter
Stuck in the 80s
[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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|