Frenchi
July 11th, 2008, 04:45 PM
Hey guys, I've problem for you. I'm running the CLI version of PHP, and having trouble getting my top level variables to be recognized inside of functions defined in external files and brought in via Include();
My code structure is like this:
// This receives operator input as to which mode to enter,
// and include()'s the necessary external file containing
// that mode's functions:
$op_mode = '';
while($op_mode == '') {
fwrite(STDOUT, "Please select operational mode (socket / terminal):\n");
$input = fgets(STDIN);
if(trim($input) == 'socket') {
require $loc."\modules\clientXML.php";
$op_mode = 'socket';
} else if(trim($input) == 'terminal') {
require $loc."\modules\\terminalControl.php";
$op_mode = 'terminal';
}
}
// This calls the main loop function, depending on which
// mode was selected:
$masterActive = true;
while($masterActive) {
if($op_mode == 'socket') {
// Client Commands
parseXML();
} else if($op_mode == 'terminal') {
// Terminal Commands
terminalCommand();
}
}
The functions run properly, they just can't see any variables declared in the main script (i.e. $masterActive). The size of the program makes it infeasible to pass every top-level variable as arguments into the included functions. Is there something I can do to 'un-blind' those included functions?
My code structure is like this:
// This receives operator input as to which mode to enter,
// and include()'s the necessary external file containing
// that mode's functions:
$op_mode = '';
while($op_mode == '') {
fwrite(STDOUT, "Please select operational mode (socket / terminal):\n");
$input = fgets(STDIN);
if(trim($input) == 'socket') {
require $loc."\modules\clientXML.php";
$op_mode = 'socket';
} else if(trim($input) == 'terminal') {
require $loc."\modules\\terminalControl.php";
$op_mode = 'terminal';
}
}
// This calls the main loop function, depending on which
// mode was selected:
$masterActive = true;
while($masterActive) {
if($op_mode == 'socket') {
// Client Commands
parseXML();
} else if($op_mode == 'terminal') {
// Terminal Commands
terminalCommand();
}
}
The functions run properly, they just can't see any variables declared in the main script (i.e. $masterActive). The size of the program makes it infeasible to pass every top-level variable as arguments into the included functions. Is there something I can do to 'un-blind' those included functions?