I have searched high and low for an answer and tried every example, but this still fails to find my classes. Why do I keep getting Fatal error: Class 'ProjectMorpheus\model\Database' not found in C:\Portables\xampp\htdocs\ProjectMorpheus\config\config.php on line 23
/ProjectMorpheus
/model
Database.class.php
/config
config.php
So my Database class has a namespace like this:
namespace ProjectMorpheus\model;
class Database { ... }
Finally, my config.php has a function autoloader function (Note: __SITE_PATH = 'C:\Portables\xampp\htdocs\ProjectMorpheus\'):
/*** auto load model classes ***/
function __autoload($class){
$parts = explode('\\', $class);
include __SITE_PATH . 'model/' . end($parts) . '.class.php';
}
$dbh = \ProjectMorpheus\model\Database::getInstance($dsn, $username, $password);
Using spl_autoloader appears to work, but why? My only guess is that $class is not the same in both instances. My spl_function looks like:
spl_autoload_register(function($class){
$parts = explode('\\', $class);
include __SITE_PATH . 'model/' . end($parts) . '.class.php';
});