What are the potential pitfalls of using extends in PHP classes?

One potential pitfall of using extends in PHP classes is that it can lead to tight coupling between parent and child classes, making the code harder to maintain and modify. To avoid this issue, consider using composition over inheritance when possible to promote code reusability without creating tight dependencies.

// Example of using composition instead of inheritance

class Logger {
    public function log($message) {
        // Log message
    }
}

class User {
    private $logger;

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

    public function createUser() {
        // Create user
        $this->logger->log('User created');
    }
}

$logger = new Logger();
$user = new User($logger);
$user->createUser();