spl_autoload_register(function ($class) { require_once __DIR__ . '/classes/' . $class . '.php'; });
require_once __DIR__ . '/vendor/autoload.php';
$loader = new \Composer\Autoload\ClassLoader(); $loader->addPsr4('MyNamespace\\', __DIR__ . '/src/'); $loader->register();This code example creates a custom autoloader using the PSR-4 standard for namespace autoloading. The `addPsr4` function maps the `MyNamespace` namespace to the `src` directory, and the `register` function registers the autoloader with PHP. Package library: PSR-4 (PHP Standard Recommendation 4) In conclusion, PHP self-loading is a powerful feature that allows programmers to write modular and extensible code. It can be used with various package libraries such as SPL, Composer, and PSR-4, among others.