What are the potential drawbacks of creating a "God-Object" in PHP, and how can they be avoided in favor of a more modular approach?

Creating a "God-Object" in PHP can lead to a monolithic and tightly coupled codebase, making it difficult to maintain, test, and scale the application. To avoid this, it's important to follow a more modular approach by breaking down the functionality into smaller, independent components that can be easily managed and tested.

// Example of a modular approach using classes and dependency injection

class Database {
    public function query($sql) {
        // Database query logic
    }
}

class UserRepository {
    private $db;

    public function __construct(Database $db) {
        $this->db = $db;
    }

    public function getUserById($id) {
        // User retrieval logic using $this->db->query()
    }
}

// Implementation
$db = new Database();
$userRepository = new UserRepository($db);
$user = $userRepository->getUserById(1);