What are some potential pitfalls to avoid when developing modular PHP applications?

One potential pitfall to avoid when developing modular PHP applications is tightly coupling modules together, which can make it difficult to update or replace individual components without affecting the entire system. To prevent this, utilize dependency injection to decouple modules and make them more reusable and maintainable.

// Bad practice: tightly coupling modules
class UserService {
    private $userRepository;

    public function __construct() {
        $this->userRepository = new UserRepository();
    }
}

// Good practice: using dependency injection
class UserService {
    private $userRepository;

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