src/Foo/Bar.php */ final class Autoloader { private static string $base = ''; public static function register(string $base): void { self::$base = rtrim($base, '/') . '/'; spl_autoload_register([self::class, 'load']); } public static function load(string $class): void { if (strncmp($class, 'AAP\\', 4) !== 0) { return; } $relative = substr($class, 4); $path = self::$base . str_replace('\\', '/', $relative) . '.php'; if (is_readable($path)) { require_once $path; } } }