This code works fine on my dev machine (Windows) but on the server it fails to load the classes:
set_include_path(get_include_path() . PATH_SEPARATOR . 'class/');
spl_autoload_extensions('.class.php');
spl_autoload_register();
I've checked the include path and that seems OK. I also attempted to include a absolute path thusly:
$application_root = $_SERVER['DOCUMENT_ROOT'];
set_include_path(get_include_path() . PATH_SEPARATOR . $application_root.'/class/');
with much the same result: the class is not loaded;
This however works:
$autoloader = function( $class_name )
{
$application_root = $_SERVER['DOCUMENT_ROOT'];
$filename = $application_root . '/class/' . str_replace( '\\', '/', $class_name) . '.class.php';
require_once $filename;
};
spl_autoload_register( $autoloader );
But is not as elegant.
How do I get spl_autoload_extensions working on my production machine?
Summary
not working;
set_include_path(get_include_path() . PATH_SEPARATOR .getenv('DOCUMENT_ROOT').'/class');
spl_autoload_extensions('.class.php');
$filter = new Filter();
With get_include_path()
I do get a complete path ".:/usr/share/pear:/usr/share/php:/home/httpd/vhosts/_hidden_/httpsdocs/class"
. I get Fatal error: Class 'Filter' not found.
working:
include getenv('DOCUMENT_ROOT').'/class/Filter.class.php';
$filter = new Filter();