$rootdir . '/class/', 'Insallah' => $rootdir . '/class/Insallah/', 'DarksLight2' => $rootdir . '/class/DarksLight2/', ]; $parts = explode('\\', $classname); $namespace = array_shift($parts); $classFile = array_pop($parts) . '.php'; if (!array_key_exists($namespace, $classMap)) { return; } $path = implode(DIRECTORY_SEPARATOR, $parts); $file = $classMap[$namespace] . $path . DIRECTORY_SEPARATOR . $classFile; if (!file_exists($file) && !class_exists($classname)) { return; } require_once $file; });