In PHP, what is the recommended approach for maintaining object instances across multiple files while ensuring proper object-oriented design principles are followed?

When maintaining object instances across multiple files in PHP, it is recommended to use a dependency injection container to manage object creation and ensure proper object-oriented design principles are followed. This approach allows for better decoupling of classes and easier testing.

// Dependency Injection Container example
class Container {
    private $instances = [];

    public function get($className) {
        if (!isset($this->instances[$className])) {
            $this->instances[$className] = new $className();
        }
        return $this->instances[$className];
    }
}

// Example usage
$container = new Container();
$object1 = $container->get('ClassName1');
$object2 = $container->get('ClassName2');