// Default is already taken
$alreadyTaken = true;
+ // Initialize instance
+ $userInstance = null;
+
// Get a registry instance
$registry = Registry::getInstance();
$userInstance = $registry->getInstance('user');
} else {
// If this instance is created then the username *does* exist
- $userInstance = User::createUserByUsername($userName);
-
- // Remember this user instance in our registry for later usage
- $registry->addInstance('user', $userInstance);
+ try {
+ $userInstance = User::createUserByUsername($userName);
+
+ // Remember this user instance in our registry for later usage
+ $registry->addInstance('user', $userInstance);
+ } catch (UsernameMissingException $e) {
+ // User was not found
+ }
}
// Does the username exist?
- if (!$userInstance->ifUsernameExists()) {
+ if ((is_null($userInstance)) || (!$userInstance->ifUsernameExists())) {
// This username is still available
$alreadyTaken = false;
}