Logs the current user out.
function user_logout() {
global $user;
watchdog('user', 'Session closed for %name.', array(
'%name' => $user->name,
));
Drupal::moduleHandler()
->invokeAll('user_logout', array(
$user,
));
// Destroy the current session, and reset $user to the anonymous user.
session_destroy();
}