How can dependencies be injected into PHP classes to avoid hidden dependencies?

To avoid hidden dependencies in PHP classes, dependencies can be injected into the class through the constructor or setter methods. This allows for better visibility of the class's dependencies and makes the code more testable and maintainable.

class MyClass {
    private $dependency;

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

    public function setDependency($dependency) {
        $this->dependency = $dependency;
    }

    // Rest of the class implementation
}