I have three files
/autoload-test.php
spl_autoload_register(function ($class) {
require_once($_SERVER['DOCUMENT_ROOT'] . '/controllers/' . $class . '.php');
});
$different_file_obj = new test;
/controllers/test.php
require_once('some_var.php');
class test {
function __construct() {
echo $GLOBALS['var'];
}
}
/controllers/some_var.php
$var = 'some value';
When I open the file 1 in browser it gives me this -> Notice: Undefined index: var in /Applications/XAMPP/xamppfiles/htdocs/avrs/controllers/test.php on line 7
But if I change the file to ->
require_once($_SERVER['DOCUMENT_ROOT'] . '/controllers/test.php');
$different_file_obj = new test;
It works fine, so I am thinking that there is some difference in including the file using the spl_autoload_register, because that is the only thing that I am changing here. Including with out the spl_autoload_register works absolutely fine.
Is there something I should know or some where I can read in details about this?