Is it advisable to extend a User class with additional functions, or does this approach lead to potential pitfalls like creating a "God class"?

Extending a User class with additional functions can be a good practice as long as the functions are related to the responsibilities of the User class. However, it is important to be mindful of creating a "God class" where a single class becomes too bloated with unrelated functions. To avoid this, consider breaking down the functionality into smaller, more focused classes or using traits to mix in additional functionality.

class User {
    private $username;

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

    public function getUsername() {
        return $this->username;
    }
}

trait UserFunctions {
    public function greetUser() {
        return "Hello, " . $this->getUsername();
    }
}

class ExtendedUser extends User {
    use UserFunctions;

    // Additional functions specific to ExtendedUser can be defined here
}

$user = new ExtendedUser("John");
echo $user->greetUser(); // Output: Hello, John