How does Dependency Injection differ from using a Registry Pattern in PHP applications?

Dependency Injection is a design pattern where components are given their dependencies rather than creating or looking for them themselves. This promotes loose coupling and makes components easier to test and maintain. On the other hand, the Registry Pattern involves using a centralized registry to store and retrieve objects or dependencies, which can lead to tight coupling and make code harder to test and maintain.

// Dependency Injection example
class UserService {
    private $userRepository;

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

$userRepository = new UserRepository();
$userService = new UserService($userRepository);
```

```php
// Registry Pattern example
class Registry {
    private static $objects = [];

    public static function set($key, $value) {
        self::$objects[$key] = $value;
    }

    public static function get($key) {
        return self::$objects[$key];
    }
}

class UserService {
    private $userRepository;

    public function __construct() {
        $this->userRepository = Registry::get('userRepository');
    }
}

$userRepository = new UserRepository();
Registry::set('userRepository', $userRepository);
$userService = new UserService();