How does PHP handle class dependencies and loading of classes during runtime?

PHP handles class dependencies and loading of classes during runtime using autoloading. Autoloading is a feature that automatically includes the necessary class files when they are needed, based on the class name and namespace. This helps reduce the manual effort of including class files and ensures that classes are available when they are needed.

// Autoloading function to load classes based on their namespace
spl_autoload_register(function ($className) {
    $classFile = str_replace('\\', '/', $className) . '.php';
    include $classFile;
});

// Example usage of autoloading
$obj = new \Namespace\ClassName();