What are the potential pitfalls of using static database objects in PHP, especially in the context of hierarchical class structures?

Using static database objects in PHP can lead to issues with maintaining state and managing dependencies, especially in the context of hierarchical class structures. To address this, consider using dependency injection to pass database objects to classes that need them, rather than relying on static methods or properties.

class Database {
    // Database connection details
}

class ParentClass {
    protected $db;

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

class ChildClass extends ParentClass {
    public function someMethod() {
        // Use $this->db to interact with the database
    }
}

// Usage
$db = new Database();
$child = new ChildClass($db);
$child->someMethod();