I have a function where I include another php script, and capture its output into a string:
function include_capture($file = NULL) {
// if no file path, dump out
if (is_null($file)) {
return NULL;
}
// using output buffering, capture output of the included file
ob_start();
include($file);
$result = ob_get_contents();
ob_end_clean();
// return output
return $result;
}
This works well, but for security reasons, I was wondering if there was any way to prevent the included script from having access to the PHP superglobals, such as $GLOBAL or $_ENV. For example, I know that in Perl its possible to restrict access to global variables by creating overriding locals:
$global_var = 'something I dont want you to see...';
sub override_global {
# set to undefined value
local $global_var = undef;
# prints nothing
print $global_var;
}
# prints the global variable
print $global_var;
Is there something similar to this in PHP, or perhaps a different technique to achieve the same result?