What are some best practices for organizing file structure and including files in PHP to avoid issues with Singleton classes?

When including files in PHP, it's important to ensure that Singleton classes are properly handled to avoid multiple instances being created. One way to organize your file structure and include files is to use an autoloader function that follows the PSR-4 standard. This will help ensure that each class is only included once and prevent issues with Singleton classes.

// Autoloader function following PSR-4 standard
spl_autoload_register(function ($class) {
    // Convert namespace separators to directory separators
    $file = __DIR__ . '/' . str_replace('\\', '/', $class) . '.php';

    if (file_exists($file)) {
        include $file;
    }
});