Maybe I'm just tired or just am simply confused, but I'm having a strange issue dealing with some require_once()
calls and ob_start()
.
Basic Structure:
Top of Main.php:
require_once 'config.php'; // includes variable $A = "bar", and Function "foo"
function getPage(){
ob_start();
include 'some_file.php';
$html = ob_get_clean();
echo $html;
die();
}
getPage();
some_file.php
require_once 'config.php'; // includes same config file
var_dump($A); // NULL
foo(); // runs, returns correct value
Config.php
$A = 'bar';
function foo(){
return "FOO";
}
So, what is wrong here? I'm including a file while buffering output. The required file config.php
holds a variable and function. When including some_file.php
during the buffer, the variable $A
is apparently NOT set/accessible. The function foo
CAN execute.