included file var scope
| From: | Evert Lammerts | Date: | Mon, 07 Apr 2008 14:32:05 +0000 |
| Subject: | included file var scope | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-272628@lists.php.net to get a copy of this message | ||
Hi all,
My system is accessible through an index.php file. This file does a bunch of includes to include global variables, which in function context become available through the global keyword:
index.php
<?php
require_once "global_vars.php";
function f() {
global $global_var;
var_dump($global_var);
}
f();
?>
However, apart from access through the index.php file I want to be able to include my index.php file from a function context:
<?php
function includeIndex() {
require_once ("index.php");
}
?>
The logical result is that variables that are globally accessible to functions when the system is accessed through index.php are now in the context of includeIndex() - so they're not global.
I want to fix this problem by not having the include inside of the function context. How to go upon this?
Evert