What are the potential pitfalls of monitoring the instantiation of a class in PHP?

One potential pitfall of monitoring the instantiation of a class in PHP is that it can lead to tight coupling between classes, making the code harder to maintain and test. To solve this issue, it is recommended to use dependency injection instead, where the dependencies of a class are injected from the outside rather than being instantiated internally.

class Dependency {
    // Class implementation
}

class MyClass {
    private $dependency;

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

$dependency = new Dependency();
$myClass = new MyClass($dependency);