Are there any best practices for organizing PHP code to ensure that required files are included at the appropriate times?

When organizing PHP code, it is important to follow best practices to ensure that required files are included at the appropriate times. One common approach is to use an autoloader function that automatically includes files when they are needed, based on class names. This helps to avoid issues with missing or duplicate includes, and keeps the codebase clean and organized.

// Autoloader function to include files based on class names
spl_autoload_register(function($class) {
    include 'classes/' . $class . '.php';
});

// Example usage of autoloader
$example = new ExampleClass();